Is there something similar to list comprehension in dict?

Michele Simionato michele.simionato at gmail.com
Fri Nov 20 09:19:43 CET 2009


On Nov 20, 4:18 am, Peng Yu <pengyu... at gmail.com> wrote:
> I'm wondering if there is something similar to list comprehension for
> dict

Yes, but only in Python 3:

>>> {(i, x) for i, x in enumerate('abc')}
{(0, 'a'), (1, 'b'), (2, 'c')}



More information about the Python-list mailing list