[Tutor] Need help with generators....

Bunny Sehgal bunnysehgal101 at gmail.com
Sat Feb 15 14:35:51 CET 2014


I am doing "Building Skills in Python". In the Generator Function example
at [url]
http://www.itmaybeahack.com/homepage/books/python/html/p02/p02c08_generators.html#generator-function-example[/url]i
can't understand, how it is working properly.
what i understood is as follows:>
1)First it makes count = 0
2)then it goes straight in for loop
3)Since the first color is red, it goes in else block and increment count
to 1 and stop execution.
4)Now its next method is called using list comprehension, and it resumes
its execution and yield its first value i.e. 1.Note that the yield
statement is outside the for loop.
5)Now there is no further yield statement which can stop execution of
countreds() function.So it raises StopExecution exception

But this is not what is happening..... why?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140215/d29c1318/attachment.html>


More information about the Tutor mailing list