O'Reilly logo
  • Sri Harsha V thinks this is interesting:

In Python 2.X range creates a physical list; in 3.X, range is an iterable that generates items on demand, so we need to wrap it in a list call to display its results all at once in 3.X only:

>>> list(range(5)), list(range(2, 5)), list(range(0, 10, 2))
([0, 1, 2, 3, 4], [2, 3, 4], [0, 2, 4, 6, 8])

From

Cover of Learning Python, 5th Edition

Note

Just to be compatible with Python 3.x I could still use list(range(...)). It produces the same result in 2.x, that is, in Python 2.x range(x,y,z) == list(range(x,y,z)).