I think you might want to check out itertools.product() https://docs.python.org/3.9/library/itertools.html#itertools.product
import itertools import string passe = 'pass' for p in itertools.product(string.ascii_lowercase, repeat = 4): p = "".join(p) if p == passe: print("Found it:", p) break else: print("Didn't find it.") Or for different lengths: foundIt = False for repeat in range(1, 6): for p in itertools.product(string.ascii_lowercase, repeat = repeat): p = "".join(p) if p == passe: print("Found it:", p) foundIt = True break if foundIt: break else: print("Didn't find it.") -- https://mail.python.org/mailman/listinfo/python-list