Kent Johnson wrote:
> Generators are not an optimization technique so much as a way to 
> structure code that includes iteration.

This recipe is a good example of how using a simple generator can 
encapsulate a bit of processing that might be awkward to include in a 
larger processing loop. Generators are really useful when you want to 
process items in a sequence, producing a new sequence, and the 
processing requires maintaining some state. A generator lets you 
encapsulate the state and the logic using the state into a function that 
is usable by client code as a simple sequence.

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496682

Kent

_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to