Am 02.01.2011 19:19, schrieb Emile van Sebille:
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])

No, it does not:

>>> l = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b']
>>>
>>> pop=l.pop
>>>
>>> dict([(pop(),pop()) for i in l])
{'a': 7, 'b': 8, 4: 3, 6: 5}
>>>
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to