I'm missing something here with range vs. xrange

John Machin sjmachin at lexicon.net
Mon Dec 10 14:44:55 EST 2007


On Dec 11, 3:55 am, "Chris Mellon" <arka... at gmail.com> wrote:
[snip]
> No. What range does is create and return a list of integers. The
> iteration is a separate step, and is traditional list iteration. In
> longhand, for x in range(y): looks something like this:
>
> range = []
> #this loop happens in C and is super-fast for small values of y, it
> #gets much much slower when y gets out of the range of pre-allocated list pools
> #and the small integer cache
> while y >= 0:
>   range.append(y)
>   y -= 1

When y is 3, the above appears to produce [3, 2, 1, 0] ...



More information about the Python-list mailing list