[Python-ideas] More on set literals

Greg Falcon veloso at verylowsodium.com
Sat Jan 26 19:37:00 CET 2008

On 1/26/08, VanL <van.lindberg at gmail.com> wrote:
> I like Raymond's suggestion (apparently adopted) that {1,2,3} is a
> frozenset literal. However, I also like the {{1,2,3}} syntax. So I would
> propose that {{}} become the literal for the *mutable* set, not the
> frozenset.

As Adam Atlas has already pointed out, {{}} already has a meaning in
the newly proposed scheme.

But that's not really the point that needs to be made.  The typical
response to this type of suggestion is to point out the obvious
technical flaw, and that's a shame, because I don't think that's the
real problem.  You could have instead suggested, say, {|1, 2, 3|} as
the new syntax for set literals.  That fixes the technical flaw, but
it still would have been, I believe, a bad idea.

I don't understand the instinct people have that every concept needs
to be generalized, that every non-uniformity in the language needs
fixing.  Normally the target is adding statements to lambdas, but
today our bikeshed is the set literal syntax.  There seems to be an
underlying assumption to these posts that I find irritiating -- that
the Python designers and developers would have added these features if
only they were smart enough to be able to think up a syntax for them
without assistance!

Raymond Hettinger's frozenset literal proposal is solid.  It
recognizes that sets created from literal notation will typically not
be mutated, that set({1,2,3}) is not a burdensome syntax in the off
cases, and that literal frozensets admit a new and faster idiom for
comparing a value against a small set of constants.

The one flaw with his proposal was his prediction:

On 1/24/08, Raymond Hettinger <python at rcn.com> wrote:
> P.S.  A small side-benefit is it may put an end for interminable requests for a {:} or {/} notation for empty sets.  There's not much need for a literal for a empty frozenset (use "not s" instead).

It turned out to only take about two days.

Greg F

More information about the Python-ideas mailing list