2009/11/20 Michele Simionato <[email protected]>: > Yes, but only in Python 3: > >>>> {(i, x) for i, x in enumerate('abc')} > {(0, 'a'), (1, 'b'), (2, 'c')}
In Python 2.x, you can do:
>>> dict((i, x) for i, x in enumerate('abc'))
{0: 'a', 1: 'b', 2: 'c'}
(Works in 2.5 - I can't remember when generator expressions were introduced.)
--
Cheers,
Simon B.
--
http://mail.python.org/mailman/listinfo/python-list
