This simple statement:
zip(xrange(0, 11614321), xrange(0, 11627964))
...is eating most of my RAM. (>150 MiB!) Why?
Edit: Ah, re-reading the docs, I see zip
returns a list, not an iterable. Anything like zip
that returns an iterable?
The larger picture: I'm iterating over two large arrays of file data, and I'm doing things like iterating (0-end, 0-end), (0-end, 1-end), etc. I'd like to not slice the array, as it would cause excessive allocations of memory. I figured I'd just iterate over the indexes instead, but that doesn't seem to work, as per above. The whole code:
def subsequence_length(data_a, data_b, loc_a, loc_b):
length = 0
for i_a, i_b in zip(xrange(loc_a, len(data_a)), xrange(loc_b, len(data_b))):
if data_a[i_a] == data_b[i_b]:
length += 1
else:
break
return length