PEP 276 Simple Iterator for ints (fwd)

Bengt Richter bokr at accessone.com
Tue Dec 11 18:41:53 EST 2001


On Tue, 11 Dec 2001 23:15:23 GMT, bokr at accessone.com (Bengt Richter) wrote:

>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]
>        ...
>
Oops, I forgot to mention steps ;-)

    for i in [0:5:2]:   # or [:5:2]
        ...




More information about the Python-list mailing list