[Python-3000] optimizing [x]range

Guido van Rossum guido at python.org
Tue Jul 31 05:41:36 CEST 2007


On 7/30/07, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> The sort of thing I have in mind is where I have a sequence
> that I want to frequently iterate over the indices of, so
> I do
>
>    r = xrange(len(myseq))
>
> so I can write
>
>    for i in r:
>      ...
>
> Having done that, if I want to test whether some index j
> is within the range of indices for this sequence, it
> seems natural to write
>
>    if j in r:
>      ...
>
> Given the context, I think this is a very Obvious Way To
> Do It, and it's surprising that it isn't as efficient as it
> looks like it should be.

Fair enough. So maybe *you* can contribute a patch?

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list