[Python-Dev] syntactic support for sets

Phillip J. Eby pje at telecommunity.com
Wed Feb 1 21:03:22 CET 2006


At 01:55 PM 2/1/2006 -0500, Greg Wilson wrote:
>I have a student who may be interested in adding syntactic support for
>sets to Python, so that:
>
>     x = {1, 2, 3, 4, 5}
>
>and:
>
>     y = {z for z in x if (z % 2)}
>
>would be legal.  There are of course issues (what's the syntax for a
>frozen set? for the empty set?),

Ones that work now:

    frozenset(z for z in x if (z%2))

    set()

The only case that looks slightly less than optimal is:

    set((1, 2, 3, 4, 5))

But I'm not sure that it warrants a special syntax just to get rid of the 
extra ().



More information about the Python-Dev mailing list