I’m getting a Memory error in Python, this isn’t surprising, but I need an alternative. So I’m using several for satements which to my knowledge store the values in memory. What should I switch the for statements to so they save it to something that won’t save to memory. Would saving it to a text file be a better route? The code is below to help answer what I should do. I’d like examples of any of your ideas.
def product(*args, **kwds):
pools = map(tuple, args) * kwds.get('repeat', 1)
result = [[]]
for pool in pools:
result = [x+[y] for x in result for y in pool]
for prod in result:
yield tuple(prod)
def start():
for chars in product("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12234567890!@#$%^&*?,()-=+[]/;", repeat = 4):
print chars
Use
itertools.product:From the documentation: