I want to create a list of string that resemble the column letters in Microsoft Excel. For example, after 26 columns, the next columns become AA
, AB
, AC
, etc.
I have tried using the modulus operator, but I just end up with AA
, BB
, CC
, etc...
import string
passes_through_alphabet = 0
for num, col in enumerate([_ for _ in range(40)]):
if num % 26 == 0:
passes_through_alphabet += 1
excel_col = string.ascii_uppercase[num%26] * passes_through_alphabet
print(num, excel_col)
0 A
1 B
2 C
3 D
...
22 W
23 X
24 Y
25 Z
26 AA
27 BB
28 CC
...