At Thursday 18/1/2007 20:26, [EMAIL PROTECTED] wrote:
def leniter(iterator):
"""leniter(iterator): return the length of an iterator,
consuming it."""
if hasattr(iterator, "__len__"):
return len(iterator)
nelements = 0
for _ in iterator:
nelements += 1
return nelements
Is it a good idea to extend the functionalities of the built-in len
function to cover such situation too?
I don't think so, because it may consume the iterator, and that's a
big side effect that one would not expect from builtin len()
--
Gabriel Genellina
Softlab SRL
__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas
--
http://mail.python.org/mailman/listinfo/python-list