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?