[issue5577] yield in iterators
Antoine Pitrou
report at bugs.python.org
Fri Mar 27 17:41:38 CET 2009
Antoine Pitrou <pitrou at free.fr> added the comment:
> More experiments:
> The tuple pair (10,20) don't correspond to (i,i*i)
This is normal, since it corresponds to ((yield i), (yield i*i)).
The value of a yield expression is what the caller puts into send(), not
what is yielded to the caller. And since you sent 10 then 20, the
resulting tuple is (10, 20).
> The yield order is distorted
It is quite logical actually. The generator first has to yield two
values before being able to produce a third one (the tuple consisting of
the value of two "yield" expressions).
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5577>
_______________________________________
More information about the Python-bugs-list
mailing list