So I need to get a function that generates a list of letters that increase from a, and end in zzz.
Should look like this:
a
b
c
...
aa
ab
ac
...
zzx
zzy
zzz
The code I currently have is this:
for combo in product(ascii_lowercase, repeat=3):
print(''.join(combo))
However, this does only increase with 3 letters, and the output is more like
a
ab
abc
abcd
...
So, to recap: Function that letters increase, and when it goes past z, it returns to aa. Thanks!
UPDATE:
I am having the same output as before. Here is what I am trying to plug it into:
a = hashlib.md5()
for chars in chain(ALC, product(ALC, repeat=1), product(ALC, repeat=1)):
a.update(chars.encode('utf-8'))
print(''.join(chars))
print(a.hexdigest())
My hash ends up like:
f1784031a03a8f5b11ead16ab90cc18e
but I expect:
415290769594460e2e485922904f345d
Thanks!
To increment a character in a Python, we have to convert it into an integer and add 1 to it and then cast the resultant integer to char. We can achieve this using the builtin methods ord and chr.
One way to iterate over a string is to use for i in range(len(str)): . In this loop, the variable i receives the index so that each character can be accessed using str[i] .
We can iterate through a list by using the range() function and passing the length of the list. It will return the index from 0 till the end of the list.
Add another loop:
for x in range(1, 4):
for combo in product(ascii_lowercase, repeat=x):
print(''.join(combo))
Output is as follows:
a
...
aa
...
aaa
...
zzz
Where ...
is a huge number of combinations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With