Ниже преобразует 0-92897 из A001-Z999, AA01-ZZ99 и печатает точки прокрутки для демонстрации:
def full_format(i):
# limit of first range is 26 letters (A-Z) times 999 numbers (001-999)
if i < 26 * 999:
c,n = divmod(i,999) # quotient c is index of letter 0-25, remainder n is 0-998
c = chr(ord('A') + c) # compute letter
n += 1
return f'{c}{n:03}'
# After first range, second range is 26 letters times 26 letters * 99 numbers (01-99)
elif i < 26*999 + 26*26*99:
i -= 26*999 # remove first range offset
cc,n = divmod(i,99) # remainder n is 0-98, use quotient cc to compute two letters
c1,c2 = divmod(cc,26) # c1 is index of first letter, c2 is index of second letter
c1 = chr(ord('A') + c1) # compute first letter
c2 = chr(ord('A') + c2) # compute second letter
n += 1
return f'{c1}{c2}{n:02}'
else:
raise OverflowError(f'limit is {26*999+26*26*99}')
# Generate all possibilities into a list for demonstration.
L = [full_format(i) for i in range(92898)]
print(L[0])
print(L[999-1])
print(L[999])
print(L[26*999-1])
print(L[26*999])
print(L[26*999+99])
print(L[26*999+99*26-1])
print(L[26*999+99*26])
print(L[26*999+99*26*26-1])
full_format(92898) # overflow
A001
A999
B001
Z999
AA01
AB01
AZ99
BA01
ZZ99
Traceback (most recent call last):
File "C:\test.py", line 31, in <module>
full_format(92898) # overflow
File "C:\test.py", line 18, in full_format
raise OverflowError(f'limit is {26*999+26*26*99}')
OverflowError: limit is 92898