Let\'s say I have a list a
in Python whose entries conveniently map to a dictionary. Each even element represents the key to the dictionary, and the following o
Another option (courtesy of Alex Martelli - source):
dict(x[i:i+2] for i in range(0, len(x), 2))
If you have this:
a = ['bi','double','duo','two']
and you want this (each element of the list keying a given value (2 in this case)):
{'bi':2,'double':2,'duo':2,'two':2}
you can use:
>>> dict((k,2) for k in a)
{'double': 2, 'bi': 2, 'two': 2, 'duo': 2}