Last active
February 19, 2016 15:21
-
-
Save goodwin64/4c7aecd6decb17b7b03d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def get_col_name(col): | |
abc = " ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
col_name = "" | |
while col > 0: | |
letter_index = col % 26 | |
if letter_index == 0: | |
letter_index = 26 | |
col -= 26 | |
col //= 26 | |
col_name = abc[letter_index] + col_name | |
return col_name.strip() | |
# uncomment lines below to output the result (delete "#" character) | |
# print(get_col_name(27)) # "AA" | |
# print(get_col_name(53)) # "BA" | |
# print(get_col_name(3702)) # "ELJ" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment