Terry Reedy tjreedy at udel.edu
Sun Oct 19 05:28:45 CEST 2008

MRAB wrote:
> On Oct 18, 7:31 pm, Terry Reedy <tjre... at udel.edu> 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 += value
> Shouldn'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.

More information about the Python-list mailing list