Print Dictionary Line by Line

Write a Python function that prints a dictionary line by line. For each line, print the key and the corresponding value.

Example 1:

Input: {"a": 1, "b": 2, "c": 3} 
Output: a: 1 b: 2 c: 3

Example 2:

Input: {"x": 10, "y": 20, "z": 30} 
Output: x: 10 y: 20 z: 30

Use a for loop to iterate over the dictionary items and print the key-value pairs.

def print_dict(dict):
for key, value in dict.items():
print(f'{key}: {value}’)

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!