[Python-3000] Python-3000 Digest, Vol 2, Issue 151

Antoine Pitrou solipsis at pitrou.net
Wed Apr 26 17:00:10 CEST 2006


Le mercredi 26 avril 2006 à 08:40 -0400, Greg Wilson a écrit :
> I think this is because:
> 
> a) sets are new to Python --- habit and examples both encourage us to use
>    lists, even when the collections in question aren't intrinsically
>    ordered; and
> 
> b) the current notation is unpleasant --- I appreciate Raymond et al's
>    dislike of egregious punctuation (it's why we all abandoned Perl,
>    right?), but {1, 2, 3} *is* a lot cleaner than set([1, 2, 3]).

I think Raymond H is right:
1) sets are most often built dynamically rather than statically (in my
own experience)
2) set([1,2,3]) makes little sense anyway, since it probably isn't
significantly more efficient than [1,2,3]

The real benefit of sets is when you have at least tens or hundreds of
elements; in that case you won't use a literal to build the set.

Another remark is that I often use sets to hold my own objects rather
than simple values (ints or strings). In a sense, I use sets as iterable
containers where arbitrary remove() is fast.





More information about the Python-3000 mailing list