Michele Simionato wrote:
On Nov 20, 4:18 am, Peng Yu <pengyu...@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')}

Although the 2.x syntax is hardly onerous:

dict ((i+5, x) for i, x in enumerate ('abc'))


-- obviously without something like the i+5, the example
equates to dict (enumerate ('abc'))
:)

TJG
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to