Dictionary to a list of tuples

EasyDictionary Programs · 84 of 94

Write a Python program to convert a dictionary to a list of (key, value) tuples.

Advertisement
Input
{"a": 19, "b": 20, "c": 21, "d": 20}
Output
[('a', 19), ('b', 20), ('c', 21), ('d', 20)]

Approach

  1. list(d.items()).

Solution

Python
print(list({"a": 19, "b": 20, "c": 21, "d": 20}.items()))
Output
[('a', 19), ('b', 20), ('c', 21), ('d', 20)]
Advertisement

Learn the concept

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

More dictionary programs

← All 94 Dictionary Programs