list 2 dict?
DevPlayer
devplayer at gmail.com
Tue Jan 4 13:18:22 EST 2011
The shorter version:
This doesn't need any x = iter(list) line. perhaps more useful if you
have a bunch of lists to be converted through out your code.
def dictit(lyst):
i = 0
while i < len(lyst):
yield lyst[i], lyst[i+1]
i = i + 2
l = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b']
{d[0]:d[1] for d in dictit(l)} 3 again a dict comprehension
func = lambda l: {k[0]:k[1] for k in dictit(l)}
d = func(l)
More information about the Python-list
mailing list