Getting some element from sets.Set

Peter Otten __peter__ at web.de
Fri May 4 02:34:22 EDT 2007


jm.suresh at no.spam.gmail.com wrote:

> It is not possible to index set objects. That is OK.
> But, what if I want to find some element from the Set.
> 
> from sets import Set
> s = Set( range(12 )
> 
> if I do pop, that particular element gets removed.
> I do not want to remove the element, but get some element
>  from the Set.
> 
> s.some_element() # Is not available
> 
> 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.

A set is probably not the appropriate container then. What is your use case?

Peter



More information about the Python-list mailing list