Getting some element from sets.Set

Raymond Hettinger python at rcn.com
Fri May 4 02:41:48 EDT 2007


> I do not want to remove the element, but get some element
>  from the Set.
 . . .
> Is there a way to do this. I am doing it like this:
>
> for x in s: break
>
> Now x is /some_element/ from s.

That is one way to do it. Another is to write:
    x = iter(s).next()

One more approach:

   x = s.pop()
   s.add(x)


Raymond Hettinger




More information about the Python-list mailing list