MRAB wrote:
On Oct 18, 7:31 pm, Terry Reedy <[EMAIL PROTECTED]> wrote:
Python provide while loops for more fine-grain control, and a protocol so *reuseable* iterators can plug into for loops. Duncan showed you both. If you *need* a doubling loop variable once, you probably need one more than once, and the cost of the doubling generator is amortized over all such uses. Any Python proprammer should definitely know how to write such a thing without hardly thinking. We can squeeze a line out of this particular example: def doubling(value, limit): while value <= limit: yield value value += valueShouldn't the upper limit be exclusive in order to be Pythonic?
Yes, and perhaps I could have mentioned that, but the OP wanted a port of the C construct.
-- http://mail.python.org/mailman/listinfo/python-list
