0

Let's suppose we want to create a loop function with billion iterations.

if we use for i in range(0, 1000000000) in Python 2 it would create a LIST with billion data members, which takes a lot of space.

By using for i in xrange(0, 1000000000), in Python 2 it doesn't create a list, but selects one index at a time.

in PYTHON 3, there is no xrange(), and range() works in either case.

How can we save space in Python 3 in this case?

pranshu vinayak
  • 133
  • 1
  • 8
  • 2
    Python 3's `range` is equivalent to python 2's `xrange`. I don't think you need to save any more space. – Aran-Fey Jun 03 '18 at 19:36
  • 1
    `range()` in Python 3 works much like `xrange()` in Python 2--almost no memory is used, and each value is calculated and given when needed. There is no function like this in Python 3 that makes a list--to do that you use `list(range(...))`. – Rory Daulton Jun 03 '18 at 19:37

0 Answers0