|
|
|
|
|
by martin_k
5289 days ago
|
|
As i said, f() returns a generator object in this case. So you're calling list on a generator that yields None once, the result of which is a list that contains None. If you change the `yield` to `yield "foobar"`, list(f()) will get you `["foobar"]`. Edit: Perhaps, to clear things up more, about where the value 7 went- your snippet can be expressed without using lambdas as >>> def g(x):
... return 7
...
>>> def f():
... v = (yield)
... g(v)
...
>>> list(f())
[None]
Note that there's no return before g(v) because generators (at least in 2.7) can only yield, not return a value. |
|