[Python-Dev] Retrieve an arbitrary element from a setwithoutremoving it
Nick Coghlan
ncoghlan at gmail.com
Fri Oct 30 16:46:01 CET 2009
Steven D'Aprano wrote:
>> So you want to introduce additional, hidden state to sets? (to make
>> sure that successive invocations return different values)
>
> If you can think of any other way to efficiently cycle over the elements
> in a set, I'm all for it :)
for x in itertools.cycle(s):
# this is an infinite loop
Having a pick() or get() method that returns an arbitrary member of a
set makes sense to me. Having any state on the set that guarantees
successive calls to get will return different values feels wrong -
creating an object with that extra state is what iter(s) is for.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
More information about the Python-Dev
mailing list