First, 987654321
is a huge number, it'll take around 8GB of free memory to represent a list of that length filled with 0
s. Your system (which appears to be 32-bit and/or has a small amount of RAM) runs out of memory with a list of that size, period; according to this post the theoretical maximum size of a list in a 32-bit CPython implementation is 536870912
elements, or in general: sys.maxsize
.
In the current system the program never gets past the first line, and you should rethink your approach, using a file or an external database will probably be a better idea. Also consider running the program in a better machine.
Second, you shouldn't use list
as a variable name, that's a built-in function and you should not shadow it. Third, the iteration loop looks wrong (see range()
's documentation to understand the expected parameters), it should be:
tableau = []
for i in xrange(987654321): # assuming Python 2.x
tableau.append(1)
Notice that there's no need to initialize the list in 0
, you can simply append elements to it. Or even simpler, if all the elements are going to be 1
, this will work as well (of course, assuming that the system didn't crash because of the huge size):
tableau = [1] * 987654321