Getting the member of a singleton set
Arnaud Delobelle
arnodel at googlemail.com
Sun May 20 23:58:10 EDT 2007
On May 21, 12:52 am, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
wrote:
[...]
> Yes, something like peek() or any() would be useful. But you're not
> restricted by the builtin methods, you could write your own:
>
> def peek(iterable):
> return iter(iterable).next()
Yes, but that's not getting rid of the ugliness, just tucking away
from sight :) *I* would know it's still there.
IMHO a 'peek' method in these container types (maybe not all iterables
because in some cases iter(it).next() changes the state of it, eg when
it is an iterator itself).
--
Arnaud
More information about the Python-list
mailing list