[Python-3000] Set literal
Jim Jewett
jimjjewett at gmail.com
Wed Jan 30 04:14:26 CET 2008
On 1/29/08, Mike Klaas <mike.klaas at gmail.com> wrote:
> 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?
> $ 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>).
Apparently you abstract your code better than I do. Many of my
mutable sets could be done that way if the iterable were described
better; in practice, I just create the set as empty and add to it.
How often is that iterable a literal? (For me, almost always, because
otherwise I usually either don't make the iterable explicit, or don't
bother turning it into a set.)
How often do you change the set again after the initial iterable is
exhausted? (I don't, but I suspect that might be a style quirk.)
-jJ
More information about the Python-3000
mailing list