Python Practice › List Programs › Program 92

Dictionary from sublists

EasyList Programs · 92 of 100

Write a Python program to create a dictionary from [key, value] sublists.

Advertisement
Input
[["a", 5], ["b", 8], ["c", 11], ["d", 14], ["e", 23]]
Output
{'a': 5, 'b': 8, 'c': 11, 'd': 14, 'e': 23}

Approach

  1. dict() accepts pairs directly.

Solution

Python
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.

More list programs

← All 100 List Programs

Leave a Comment