[Python-Dev] Retrieve an arbitrary element from a setwithoutremoving it
python at rcn.com
Tue Oct 27 20:49:01 CET 2009
> Was it ever decided whether this would fall under the moratorium?
Decided isn't the right word:
FWIW, I'm a strong -1 on both proposals.
Just add a short get_one() function and a get_equivalent() recipe
to your utils directory. That will get the job done (thought I don't
expect that you will *ever* make much use of either one).
No need to complexify a type that is currently very simple.
P.S. get_equivalent: http://code.activestate.com/recipes/499299/
get_one = lambda s, default=None: next(iter(s), default)
The first works with all type that defines __contains__.
The second works for any iterable.
Neither of these concepts are specific to set objects.
More information about the Python-Dev