In this python dictionary program, we will convert a key-values list to a flat dictionary.
Steps to solve the program
- Take a list having a list of values as input.
Convert a key-values list to a flat dictionary using zip() and dict().
- Zip() will convert the list of values into a key-value pair.
- Print the output.
dict1 = {'name':['Apr','May','June'],'month':[4, 5, 6]}
res = dict(zip(dict1['name'],dict1['month']))
print(res)
Output :
{'Apr': 4, 'May': 5, 'June': 6}