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

Willi Richert w.richert at gmx.net
Fri Oct 30 09:16:02 CET 2009


Am Freitag, 30. Oktober 2009 03:58:16 schrieb Steven D'Aprano:
> To clarify point 3, given:
> 
> x = set.get()
> y = set.get()
> 
> then x and y will only be the same element if set has length one. 
> However, given:
> 
> x = set.get()
> set.add(el)
> set.remove(el)
> y = set.get()
> 
> there are no guarantees about x and y being different.
> 
> I believe that the patch supplied by Willi Richart implemented these 
> behaviours.
> 
> http://bugs.python.org/issue7212
> 


Actually, no. The patch makes no assumption about x and y being different.

It does not try to extend the core functionality of set nor does it need to 
maintain any state that would be necessary for that. 

It is just a more obvious and cleaner way for saying "for x in some_set: 
break". So, as Raymond says, it is the Pythonic version of "arb" in setl.


wr


More information about the Python-Dev mailing list