list comprehension question
Neil Schemenauer
nas at python.ca
Mon Mar 25 14:33:23 EST 2002
Tim Peters wrote:
> No. len([f(x) for x in y]) == len(y) whenever no exception occurs,
> regardless of the form of f() or type of y.
Looks like the bot needs a bugfix:
>>> def f():
... for x in range(10):
... yield x
...
>>> len(f)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: len() of unsized object
>>> len([int(x) for x in f()])
10
Hmm, should len() should work on pure iterators?
Neil
More information about the Python-list
mailing list