Python Practice › Dictionary Programs › Program 53
List of tuples to a dictionary
Write a Python program to convert a list of pairs into a dictionary.
Input
[("mike", 1), ("Sarah", 20), ("Jim", 16)]Output
{'mike': 1, 'Sarah': 20, 'Jim': 16}Approach
dict(pairs).
Solution
print(dict([("mike", 1), ("Sarah", 20), ("Jim", 16)]))Output
{'mike': 1, 'Sarah': 20, 'Jim': 16}Learn the concept
New to this topic? Read the lesson, then come back.