List of tuples to a dictionary

EasyDictionary Programs · 53 of 94

Write a Python program to convert a list of pairs into a dictionary.

Advertisement
Input
[("mike", 1), ("Sarah", 20), ("Jim", 16)]
Output
{'mike': 1, 'Sarah': 20, 'Jim': 16}

Approach

  1. dict(pairs).

Solution

Python
print(dict([("mike", 1), ("Sarah", 20), ("Jim", 16)]))
Output
{'mike': 1, 'Sarah': 20, 'Jim': 16}
Advertisement

Learn the concept

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

More dictionary programs

← All 94 Dictionary Programs