Is using range() in for loops really Pythonic?

cokofreedom at gmail.com cokofreedom at gmail.com
Wed May 14 03:24:39 EDT 2008


On May 14, 8:37 am, Marc 'BlackJack' Rintsch <bj_... at gmx.net> wrote:
> On Tue, 13 May 2008 10:20:41 -0700, John Nagle wrote:
> > Matt Nordhoff wrote:
>
> >> Well, you should use "xrange(10)" instead of "range(10)".
>
> >    CPython really is naive.  That sort of thing should be a
> > compile-time optimization.
>
> It's not naive, it can't know at compile time what object is bound to the
> name `xrange` at runtime.
>
> Ciao,
>         Marc 'BlackJack' Rintsch

I think he meant you should just use xrange over range at all times.



More information about the Python-list mailing list