On May 14, 3:24 pm, gerardob <gberbeg...@gmail.com> wrote:
> Hello, let S be a python set which is not empty
> (http://docs.python.org/library/sets.html)
>
> i would like to obtain one element (anyone, it doesn't matter which one) and
> assign it to a variable.
>
> How can i do this?

x = next(iter(s))

or you can supply a default value in case the set is empty:

x = next(iter(s), default_value)


Raymond
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to