Python Practice › Dictionary Programs › Program 84
Dictionary to a list of tuples
Write a Python program to convert a dictionary to a list of (key, value) tuples.
Input
{"a": 19, "b": 20, "c": 21, "d": 20}Output
[('a', 19), ('b', 20), ('c', 21), ('d', 20)]Approach
list(d.items()).
Solution
print(list({"a": 19, "b": 20, "c": 21, "d": 20}.items()))Output
[('a', 19), ('b', 20), ('c', 21), ('d', 20)]Learn the concept
New to this topic? Read the lesson, then come back.