Created
February 18, 2018 01:55
-
-
Save adamb70/91e6ed942c464ebeecd6de90112612ef to your computer and use it in GitHub Desktop.
Converts spreadsheet-style column names (A, B, AA, etc) of any length into an integer index, such that A==0, B==1, AA==26, etc. Use upper or lower case.
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 col(letters): | |
""" Convert column letters into zero-indexed number """ | |
letters = letters.lower() | |
num = 0 | |
for l in letters[:-1]: | |
num += (ord(l) - 96) * 26 | |
num += (ord(letters[-1]) - 96) | |
return num - 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment