itertools product uses too much memory

Viewed 2179

I only have two sentences that I want to produce variations and compute the leveshtein distance of, but when trying to produce this list with itertools even my 64GB RAM machine gets overloaded.

Is there a way to limit this, even if I have to limit it to a certain number of combinations.

here is my code so far:

from __future__ import print_function
import itertools
import sys

in_file = sys.argv[1]
X = []


with open(in_file) as f:
        lis = list(f)
X.append([' '.join(x) for x in itertools.product(*map(set, zip(*map(str.split, lis))))])

for x in X:
        print x
1 Answers
Related