Map two lists to a dictionary

EasyDictionary Programs · 25 of 94

Write a Python program to map a list of keys to a list of values.

Advertisement
Input
["name", "sport", "rank", "age"], ["Virat", "cricket", 1, 32]
Output
{'name': 'Virat', 'sport': 'cricket', 'rank': 1, 'age': 32}

Approach

  1. dict(zip(...)).

Solution

Python
keys = ["name", "sport", "rank", "age"]values = ["Virat", "cricket", 1, 32]print(dict(zip(keys, values)))
Output
{'name': 'Virat', 'sport': 'cricket', 'rank': 1, 'age': 32}
Advertisement

Learn the concept

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

More dictionary programs

← All 94 Dictionary Programs