10 ways to convert python lists to dictionaries

PHOTO EMBED

Tue Oct 20 2020 11:26:52 GMT+0000 (Coordinated Universal Time)

Saved by @tharun #python

from itertools import zip_longest
l1=[1,2,3,4,5,6,7]
l2=['a','b','c','d']
d1=zip_longest(l1,l2,fillvalue='x')
print (d1)#Output:<itertools.zip_longest object at 0x00993C08>
#Converting zip object to dict using dict() contructor.
print (dict(d1))
#Output:{1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'x', 6: 'x', 7: 'x'}
content_copyCOPY

to convert lists of lists of lists to dictionaries in python

https://medium.com/better-programming/10-ways-to-convert-lists-to-dictionaries-in-python-d2c728d2aeb8