Iterate over a dictionary

EasyDictionary Programs · 19 of 94

Write a Python program to loop over a dictionary and print each key and value.

Advertisement
Input
{"food": "burger", "type": "fast food"}
Output
food : burger
type : fast food

Approach

  1. for k, v in d.items().

Solution

Python
d = {"food": "burger", "type": "fast food"}for key, value in d.items():    print(key, ":", value)
Output
food : burger
type : fast food
Advertisement

Learn the concept

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

More dictionary programs

← All 94 Dictionary Programs