PEP 276 Simple Iterator for ints (fwd)

Bengt Richter bokr at accessone.com
Tue Dec 11 18:15:23 EST 2001


On Tue, 27 Nov 2001 10:27:31 -0800, James_Althoff at i2.com wrote:

>
>Greg Ewing wrote:
>>While trying to think of a range syntax that looks
>>unambiguously half-open without clashing with list
>>or tuple constructors, the following blindingly
>>obvious solution occurred to me:
>>
>>  for 0 <= i < 5:
>>    ...
>
>Greg,
>
>Since this looks like a suggestion for replacing xrange in the general
>case, did you have any thoughts on how one might specify a step value?
>

How about if a bare [x:y:z] were interepreted as an abbreviation for slice(x,y,z)
and you defined what one might expect as an iterator for the slice type?

Then you could write
    for i in [0:5]:   # or [:5]
        ...




More information about the Python-list mailing list