[Python-3000] Set literal

Jim Jewett jimjjewett at gmail.com
Mon Jan 28 15:42:04 CET 2008


On 1/28/08, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Guido van Rossum wrote:
> > On Jan 26, 2008 8:39 PM, Raymond Hettinger <python at rcn.com> wrote:

> >>However, my support for it has waned anyway.  The
> >> notation is also used for set comprehension
> >> and those should be mutable.

Set comprehensions don't appear yet in 2.5, so they aren't yet an
immovable constraint.

How often are set comprehensions needed, and how often must they be mutable?

In my own code, I already tend to treat even the results of a list
comprehension as immutable.  Normally, the result is already a
complete set, and when it isn't, the code is already awkward as I
digress to get the other members.

    res = tupleA + tupleB

wouldn't really be any worse than

    res.extend(listB)

and I would actually prefer

    res = setA.union(setB)

> Another possibility would be to drop set comprehension
> syntax and just require people to use set(genexp).

This looks fine to me, but again, I usually just iterate through it
once, so I typically use list even when a set would be more
semantically correct.

> Or have set comprehensions produce frozensets and require
> set(genexp) to get a mutable set.

Absolutely ... why are the default sets mutable?  When I want a
mutable set, I almost always start with an empty set.  Even when I
have initial members, they usually come from another container, and
turning them into a set is (mentally) more of a casting than a
comprehension.

-jJ


More information about the Python-3000 mailing list