list 2 dict?

Emile van Sebille emile at fenx.com
Sun Jan 2 13:19:27 EST 2011


On 1/2/2011 8:31 AM Stefan Sonnenberg-Carstens said...

> A last one:
>
> l = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b']
> dict((x[1],x[0]) for x in ((l.pop(),l.pop()) for x in xrange(len(l)/2)))

This also works:


l = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b']

pop=l.pop

dict([(pop(),pop()) for i in l])




More information about the Python-list mailing list