[issue7212] Retrieve an arbitrary element from a set without removing it

Raymond Hettinger report at bugs.python.org
Thu Nov 5 19:42:07 CET 2009

Raymond Hettinger <rhettinger at users.sourceforge.net> added the comment:

After a long discussion on python-dev, this proposal is rejected in
favor of adding documentation notes on the ways to non-destructively
retrieve an arbitrary item from a set or frozenset.

Here is an except from the end of the thread:

[Steven D'Aprano]
>> Anyway, given the level of opposition to the suggestion, I'm no longer
>> willing to carry the flag for it. If anyone else -- perhaps the OP --
>> feels they want to take it any further, be my guest.

[geremy condra]
> I've said before that I'd like there to be one, standard way of
> doing this. A function call- set.pick() seems reasonably named
> to me- is probably the cleanest way to do that. Absent that,
> an example in the docs that illustrates the preferred idiom
> would be great. 

Summarizing my opposition to a new set method:
1) there already are at least two succinct ways to get the same effect
2) those ways work with any container, not just sets
3) set implementations in other languages show that this isn't needed.
4) there is value to keeping the API compact
5) isn't needed for optimization (selecting the same value in a loop
makes no sense)
6) absence of real-world code examples that would be meaningfully improved

[Terry Reedy]

I would be happy to add an example to the docs so that this thread
can finally end.

[Eric Smith]
Please do!

[Terry Reedy]

Leaving this open until I've done the documentation patch.

priority:  -> low
resolution:  -> rejected

Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list