Python Practice › Dictionary Programs › Program 52
Two lists in a dict to one flat dict
Write a Python program to pair the two list values of a dictionary into a flat dictionary.
Input
{"name": ["Apr", "May", "June"], "month": [4, 5, 6]}Output
{'Apr': 4, 'May': 5, 'June': 6}Approach
zipthe two lists.
Solution
d = {"name": ["Apr", "May", "June"], "month": [4, 5, 6]}print(dict(zip(d["name"], d["month"])))Output
{'Apr': 4, 'May': 5, 'June': 6}Learn the concept
New to this topic? Read the lesson, then come back.