I have two high-dimension lists of integers. The dimension of each list is over 200000. My task is like this: given two list
a = [None, 0, None, None, 0, None, None, None, 0, None, None, None, None, None, 0,...]
b = [7 1 4 8 2 1 1 1 1 6 1 6 1 4 4 1 1 6 6 7 4 4 7 5...]
the number of Noneequals to the length of b
My question is how to replace all None of a with each element in busing minimum memory.
My method is
j = 0
for i in range(len(a)):
if a[i] == None:
while j < len(b):
a[i] = b[j]
break
j = j+1
Since my program consumes memory much, I really need to save memory use. Could you please give me some ideas on how to save the memory in this situation?
xrangeinstead ofrange, since that's the only thing in your code that uses any significant amount of memory. The arraysaandboccupy memory too, of course, but since those are the inputs you can't avoid that in this code.