Generate custom alpha numeric sequence

后端 未结 2 1908
耶瑟儿~
耶瑟儿~ 2021-01-23 02:32

I am trying to generate custom alpha numeric sequence. The sequence would be like this :

AA0...AA9 AB0...AB9 AC0...AC9..and so on..

In short, there are 3 places

2条回答
  •  抹茶落季
    2021-01-23 03:08

    this is a way to do just that:

    from itertools import product
    from string import ascii_uppercase, digits
    
    for a, b, d in product(ascii_uppercase, ascii_uppercase, digits):
        print(f'{a}{b}{d}')
    

    string.ascii_uppercase is just 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; string.digits is '0123456789' and itertools.product then iterates over all combinations.

    instead of digits you could use range(10) just as well.

提交回复
热议问题