for element in allElements[400:501]:
doSomething(element)
Python .
Instead, I would use:
for index in xrange(400, 501):
doSomething(allElements[index])
This method also allows you to manipulate list indices during iteration.
EDIT: in Python 3.0 you can use range()
instead xrange()
, but in version 2.5 and earlier it range()
creates a list and xrange()
creates a generator that eats less than your precious memory.
Abgan source
share