Using something like this will work without taking much memory:
import itertools
import string
for guess in itertools.product(string.lowercase, repeat=6):
if checkguess(''.join(guess)):
print("Password is: {0}".format(''.join(guess)))
itertools.product
generates the possible combinations one by one. It does not return anything, it is a generator function. See the python documentation. All the functions in itertools
behave like or handle iterators, hence the name.
If your code takes up much memory, you might want to post it here, so we may find the culprit.
Based on DSM's suggestion for faster code, you can do something like this:
import string
from itertools import product, combinations, permutations
for guess_chars in combinations(string.lowercase, 4):
for doubled_chars in combinations(guess_chars, 2):
for guess in permutations(guess_chars + doubled_chars):
#...