Iterate a to zzz in python

前端 未结 2 718
滥情空心
滥情空心 2021-01-13 03:29

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
         


        
相关标签:
2条回答
  • 2021-01-13 04:15
    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))
    

    RESPONDING TO THE QUESTION UPDATE

    I tried all the methods, but couldn't get 415290769594460e2e485922904f345d what you mentioned you expect.. so I don't know how you calculated your expectation.

    product                       : 1a431d62ffffd9e78e1b22f8245ad945d0
    permutations                  : 52d2529adf73975a4ca82bc7e25db4c6
    combinations                  : 52bf3fcd925b2fdc1c52df70b7e33cbb
    combinations_with_replacement : 421d5ff16fc211ae253fcc3e81eeb262
    
    0 讨论(0)
  • 2021-01-13 04:30

    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.

    0 讨论(0)
提交回复
热议问题