how to make a generator use the last yielded value when it regains control

John Salerno johnjsal at NOSPAMgmail.com
Fri Apr 7 00:22:26 EDT 2006


Ben Cartwright wrote:

> Definitely go for (1).  The Morris sequence is a great candidate to
> implement as a generator.  As a generator, it will be more flexible and
> efficient than (2).

Actually I was just thinking about this and it seems like, at least for 
my purpose (to simply return a list of numbers), I don't need a 
generator. My understanding of a generator is that you do something to 
each yielded value before returning to the generator (so that you might 
not return at all), but since I'm not handling the individual numbers, 
just getting a list, it seems I don't need them to be yielded. Of 
course, a generator would allow the process to be done over and over, I 
suppose, which is what I wanted, I just couldn't figure out how to keep 
using the new values.



More information about the Python-list mailing list