Suggestion for impriving list comprehensions
Neil Schemenauer
nas at python.ca
Fri Jul 27 21:08:57 EDT 2001
Tom Good wrote:
> Consider the following:
>
> >>> from __future__ import generators
> >>> def g():
> ... yield 1
> ... yield 2
> ...
> >>> i = iter(g)
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> TypeError: iter() of non-sequence
> >>>
>
> iter(g) doesn't work, but it somehow feels as if it should.
What could iter(g) possibly mean? This seems to be some very weird
confusion about a function object and the object a function returns.
Are you surprised when:
def one():
return 1
print one + 2
does not print 3?
Neil
More information about the Python-list
mailing list