Created
September 30, 2010 13:26
-
-
Save flegoff/604570 to your computer and use it in GitHub Desktop.
A base26 (A->Z) looping counter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## A base26 (A->Z) looping counter | |
# | |
# AAA, AAB, AAC.... ZZY, ZZZ, AAA | |
l_input = 'AAA' | |
l_output = '' | |
ret = 1 | |
for e in l_input[::-1]: | |
new = (ord(e) - 65 + ret) % 26 | |
ret = (not new and ret) and 1 or 0 | |
l_output += chr(new + 65) | |
l_output = l_output[::-1] | |
print l_output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment