[Python-Dev] Retrieve an arbitrary element from a set withoutremoving it

Georg Brandl g.brandl at gmx.net
Fri Oct 30 21:37:36 CET 2009

Steven D'Aprano schrieb:
> On Wed, 28 Oct 2009 04:47:59 am Raymond Hettinger wrote:
>> A dict.get() can be meaningfully used in a loop (because the key can
>> vary). A set.get() returns the same value over and over again
>> (because there is no key).
> I don't believe anyone has requested those semantics. The suggested 
> semantics for set.get() with no arguments, as I understand them, are:
> (1) it will only fail if the set is empty;
> (2) it should be efficient;
> (3) if you call it repeatedly on a set without modifying the set, you 
> will cycle through each element in turn in some unspecified arbitrary 
> order.

I don't like this.  It gives a set object a hidden state, something that
AFAICS no other builtin has.  Iterating over an iterable is what iterators
are for.


Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.

More information about the Python-Dev mailing list