improving speed of nested python for-loops which append lists

Viewed 25

Inside my nested for-loops I am doing some calculations which are appended to lists. In some cases the for-loops will be huge generating lists that are hundreds of millions and even billions of entries. When the lists gets huge it seems to fill up memory slow things down.

Anyone having suggestions for how I can execute the below quicker? Alternative ways to set it up which doesn't drain memory?

n = 10000 #This number can be much higher
m = 10000 #This number can be much higher
x = []
y = []
a = 1
for n in range(n):
    b = 1
    for m in range(m):
        x.append(a+b) 
        y.append(a+b*2)
    b = b+1
a = a+1
0 Answers
Related