dict comprehension

Arnaud Delobelle arnodel at googlemail.com
Fri Feb 1 02:13:37 EST 2008


On Feb 1, 6:21 am, "Terry Reedy" <tjre... at udel.edu> wrote:
> "Daniel Fetchinson" <fetchin... at googlemail.com> wrote in message
>
> news:fbe2e2100801312151x7136d1bbu3498d7d21728100e at mail.gmail.com...
> | Hi folks,
> |
> | There is a withdrawn PEP about a new syntax for dict comprehension:
> |http://www.python.org/dev/peps/pep-0274/which says:
>
> I believe both set and dict comprehensions will be in 3.0.

Python 3.0a1+ (py3k:59330, Dec  4 2007, 18:44:39)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> {x*x for x in range(10)}
{0, 1, 4, 81, 64, 9, 16, 49, 25, 36}
>>> {x:x*x for x in range(10)}
{0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81}
>>>

That's nice.

--
Arnaud




More information about the Python-list mailing list