Problem with Python xrange

Diez B. Roggisch deetsNOSPAM at web.de
Sun Jun 6 16:29:56 EDT 2004


Christian Neumann wrote:
 
> x[1:4]  ## It should be return an xrange object with length 3
> Is this really a bug?

No. xrange doesn't create an actual sequence you can slice, instead it
creates an iterable object usable in for ... in ... statements.

The reason is that its much more memory-consuming to create a list if all
you are interested in are only the generated indices.

Use range, if you really want a list.
-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list