Square of every value

EasyDictionary Programs · 2 of 94

Write a Python program to print the square of every value in a dictionary.

Advertisement
Input
{"a": 5, "b": 3, "c": 6, "d": 8}
Output
a : 25
b : 9
c : 36
d : 64

Approach

  1. Loop over items().

Solution

Python
d = {"a": 5, "b": 3, "c": 6, "d": 8}for key, value in d.items():    print(key, ":", value ** 2)
Output
a : 25
b : 9
c : 36
d : 64
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More dictionary programs

← All 94 Dictionary Programs