Why is this loop heavy code so slow in Python? Possible Project Euler spoilers

Paul Rubin http
Sun Sep 2 13:05:27 EDT 2007


aleax at mac.com (Alex Martelli) writes:
> ...which suggests that creating an xrange object is _cheaper_ than
> indexing a list...

Why not re-use the xrange instead of keeping a list around?

    Python 2.4.4 (#1, Oct 23 2006, 13:58:00) 
    >>> a = xrange(3)
    >>> print list(a)
    [0, 1, 2]
    >>> print list(a)
    [0, 1, 2]



More information about the Python-list mailing list