Square of every value
Write a Python program to print the square of every value in a dictionary.
{"a": 5, "b": 3, "c": 6, "d": 8}a : 25 b : 9 c : 36 d : 64
Approach
- Loop over
items().
Solution
d = {"a": 5, "b": 3, "c": 6, "d": 8}for key, value in d.items(): print(key, ":", value ** 2)a : 25 b : 9 c : 36 d : 64
Learn the concept
New to this topic? Read the lesson, then come back.