Python Practice › List Programs › Program 92
Dictionary from sublists
Write a Python program to create a dictionary from [key, value] sublists.
Input
[["a", 5], ["b", 8], ["c", 11], ["d", 14], ["e", 23]]
Output
{'a': 5, 'b': 8, 'c': 11, 'd': 14, 'e': 23}Approach
dict()accepts pairs directly.
Solution
print(dict([["a", 5], ["b", 8], ["c", 11], ["d", 14], ["e", 23]]))Output
{'a': 5, 'b': 8, 'c': 11, 'd': 14, 'e': 23}Learn the concept
New to this topic? Read the lesson, then come back.