dict comprehension

Wildemar Wildenburger lasses_weil at klapptsowieso.net
Fri Feb 1 08:38:59 EST 2008


Arnaud Delobelle wrote:
>> 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}
> 
OK, not bad. But I don't really see how this is better than the 
generator approach.

Also, what is that first thing? A valueless dict (and thus a set)?

/W



More information about the Python-list mailing list