[Python-3000] sets in P3K?

Alex Martelli aleaxit at gmail.com
Tue Apr 25 04:17:45 CEST 2006


On Apr 24, 2006, at 6:35 PM, Greg Wilson wrote:

>> Ian Bicking:
>> Instead you get set([2, 3, 5, 7]), which is much less attractive and
>> introduces an unneeded intermediate data structure.  Or set((2, 3, 5,
>> 7))... which is typographically prettier, but probably more  
>> confusing to
>> a newbie.
>>
>> Generator comprehensions + dict() were a nice alternative to dict
>> comprehension, and also replace the need for set comprehension.  I  
>> feel
>> like there might be some clever way to constructing sets?  Not that
>> there's any direct relation to generator expressions that I can  
>> see, but
>> maybe something in the same vein.
>
> One of the reasons I'd like native syntax for sets is that I'd like  
> set
> comprehensions:
>
>     a = {b for b in c where b > 0}
>
> may not quite be as beautiful as using epsilon for membership  
> (sorry, Alex
> ;-), but it's still quite nice.

I think set(b for b in c if b > 0) is much nicer -- two separate  
issues, using 'where' instead of 'if' doesn't seem to buy anything,  
and the distinct one of using {} rather than set(), and on EACH of  
them I strongly prefer today's syntax.


Alex




More information about the Python-3000 mailing list