convert loop to list comprehension

MonkeeSage MonkeeSage at gmail.com
Sat Sep 9 03:14:10 CEST 2006


Paul Rubin wrote:
> "MonkeeSage" <MonkeeSage at gmail.com> writes:
> > Ps. I don't know if xrange is faster...I thought the difference was
> > that range created a temporary variable holding a range object and
> > xrange created an iterator?
>
> There's no such thing as a "range object"; range creates a list, which
> consumes O(n) memory where n is the number of elements.  xrange
> creates an xrange object, which is a reusable iterator of sorts.

Aha, thanks for explaining. :)

Regards,
Jordan




More information about the Python-list mailing list