[Python-3000] Set literal

Mike Klaas mike.klaas at gmail.com
Wed Jan 30 01:18:39 CET 2008


On 29-Jan-08, at 2:29 PM, Greg Ewing wrote:

> Jim Jewett wrote:
>
>> The majority of uses need a mutable set that starts empty.
>
> Does anyone have evidence to support that assertion?
>
> Thinking about my own code, I probably do membership
> tests on constant sets (represented as tuples) about as
> often as I build up mutable sets (or some equivalent data
> structure).

over 120k loc:

All uses of set():

$ pygrep '[^.a-z]set[(]' | grep -v unittest | wc
     320    1583   24774

Empty set():

$ pygrep '[^.a-z]set[(][)]' | grep -v unittest | wc
     114     478    7406

Some of the uses in the first group could be replaced with frozenset,  
of course.  Looking at the examples, though, I would say that most of  
the uses of sets start out using a set constructed using  
comprehension or set(<iterable>).

I think that 'set()' is a perfectly fine and readable empty set  
"literal".

-Mike


More information about the Python-3000 mailing list