You should think of "AAA", "ZZZ", ... as a representation of the value you are manipulating.
First, let's analyze the value:
val = sum(pow(26, i) * (ord(v) - ord('A') + 1) for i, v in enumerate(value[::-1]))
Then add the value to it:
val = val + 1
Edit
The final value is set:
res = "" while val > 0: val, n = divmod(val - 1, 26) res = chr(n+ord('A')) + res
The lack of a representation for zero requires that the value passed to divmod decrease on each turn, which I did not find a way to do with understanding the list.
Edit
Instead of ord() and chr() you can use string.ascii_uppercase.index() and string.ascii_uppercase[]
source share