[Tutor] For Loop question
kent37 at tds.net
Fri Jun 27 13:22:22 CEST 2008
On Fri, Jun 27, 2008 at 2:45 AM, Mark Tolonen <metolone+gmane at gmail.com> wrote:
> The above solutions create new lists. If a functional requirement is to
> modify the list in place, then the original is fine (on Python 2.6 and
> later) or should use xrange instead of range (on Python 2.5 or earlier,
> especially for large lists).
range() has not changed it Python 2.6, it still returns a list. 2.6
makes only backwards-compatible changes.
The Python 2.6 docs say, "The advantage of xrange() over range() is
minimal (since xrange() still has to create the values when asked for
them) except when a very large range is used on a memory-starved
machine or when all of the range's elements are never used (such as
when the loop is usually terminated with break)."
More information about the Tutor