I need to write generator which yield all possible 8 symbols strings.
From array of symbols like this:
leters = ['1','2','3','4','5','6','7','8','9','0','q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m']
The skeleton looks like this:
def generator():
"""
here algorithm
"""
yield string
suppose to return list like this ['00000001','00000002','00000003', ......'mmmmmmmm']
itertools.combinations()anditertools.combinations_with_replacement()return a generatorI am using
print()in the examples to illustrate the output. Substitute it withyield, to get a generator.If you brute force it for all 8 letter passwords containing english letters and digits, you’re looking to iterate over ~ 2.8 trillion strings
EDIT
If you somehow know there are no repeated elements, use
permutationsthis gives you both ab and ba
For the most general brute force sequence use
itertools.product()as in Cosmologicon’s solution