--- Dick Moores <[EMAIL PROTECTED]> wrote: > > Andrei's > Write your own iterator: > >>> def hugerange(minval, maxval): > ... val = minval > ... while val < maxval: > ... yield val > ... val += 1 > > All 3 are essentially the same, aren't they. Which > makes me feel even > dumber, because I don't understand any of them. I've > consulted 3 > books, and still don't understand the use of yield. >
This is an example of a "coroutine". See http://en.wikipedia.org/wiki/Coroutine def hugerange(minval, maxval): val = minval while val < maxval: yield val ### return value of "val" to calling routine ### at this point and place ### hugerange() function temporarily ### on hold ... ### ### next call to hugerange() ### resumes at this point with ### all previous variable values ### still intact ... val += 1 __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor