I have:
somelist = ['a', 'b', 'c', 'd']
I want this list converted to dict
somedict = {'a' : 1, 'b' : 1, 'c' : 1, 'd' : 1}
So I did:
somedict = dict(zip(somelist, [1 for i in somelist]))
it works, but not sure if this is the most efficient or pythonic way to do it
Any other ways to do this, preferably the easiest way?
source
share