Getting some element from sets.Set

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Wed May 9 13:12:08 EDT 2007


In <1178725344.400736.210280 at n59g2000hsh.googlegroups.com>,
tutufan at gmail.com wrote:

> Since any element of the set serves as a name (and you know the sets are
> all non- empty), it'd be very nice to have a .element() method, or some
> such. I guess "iter(s).next()" works okay, but it's not very readable,
> and I wonder if it's efficient.

Give it a name and it gets more readable:

def get_name(setobj):
    return iter(setobj).next()

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list