[Python-Dev] Retrieve an arbitrary element from a set without removing it
Terry Reedy
tjreedy at udel.edu
Mon Oct 26 17:02:05 CET 2009
Alexander Belopolsky wrote:
> Here is an alternative idea on how storing interned objects in a set
> can be supported. Currently set.add method returns None and had no
> effect when set already has an object equal to the one being added. I
> propose to consider changing that behavior to make set.add return the
> added object or the set member that is equal to the object being
> added. It is unlikely that many programs rely on the return value
> being None (with doctests being a probable exception), so adding this
> feature is unlikely to cause much grief.
I had exactly the same idea, but did not post because it violates the
general rule that mutators return None. On the other hand, the returned
value here would not be the mutated collection, so no chaining is
possible. And 'add' is clearly intended to change something.
On the other hand, frozensets do not have an add method.
Terry Jan Reedy
More information about the Python-Dev
mailing list