Iterate a on zzz in python

So I need to get a function that generates a list of letters that increase with a and end with zzz.

It should look like this:

a
b
c
...
aa
ab
ac
...
zzx
zzy
zzz

The code I have is the following:

for combo in product(ascii_lowercase, repeat=3):
            print(''.join(combo))

However, this will only increase by 3 letters, and the result is more like

a
ab
abc
abcd
...

So, recall: A function that increments letters, and when it passes by z, it returns to aa. Thank!


UPDATE:

I have the same result as before. Here is what I am trying to connect to it:

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 like this:

f1784031a03a8f5b11ead16ab90cc18e

but I expect:

415290769594460e2e485922904f345d

Thank!

+4
source share
2 answers
from string import ascii_lowercase as ALC
from itertools import chain, product

for chars in chain(ALC, product(ALC, repeat=2), product(ALC, repeat=3)):
    print(''.join(chars))

RESPONSE TO UPDATE QUESTION

, 415290769594460e2e485922904f345d , , .. , .

product                       : 1a431d62ddd9e78e1b22f8245ad945d0
permutations                  : 52d2529adf73975a4ca82bc7e25db4c6
combinations                  : 52bf3fcd925b2fdc1c52df70b7e33cbb
combinations_with_replacement : 421d5ff16fc211ae253fcc3e81eeb262
+5

:

for x in range(1, 4):
    for combo in product(ascii_lowercase, repeat=x):
        print(''.join(combo))

:

a
...
aa
...
aaa
...
zzz

... - .

+8

Source: https://habr.com/ru/post/1540770/


All Articles