You know, like A = 1, B = 2 etc. I could just make a long list of if-thens, but maybe there's already a module for it.
Bonus if it works like it does in "Excel Coordinates" where AA = 27 and continues. (Does this count as base26 numbers?)
You know, like A = 1, B = 2 etc. I could just make a long list of if-thens, but maybe there's already a module for it.
Bonus if it works like it does in "Excel Coordinates" where AA = 27 and continues. (Does this count as base26 numbers?)
def foo(c):
return ord(c) - 64
foo('A')
1
foo('B')
2
off the top of my head :p
from string import ascii_uppercase
letterKey = dict(list(zip( ascii_uppercase, range(1, 27))))
And as for the excel cords:
geExceltValue = lambda string: sum([26**i * list(reversed(map(lambda x: letterKey[x], string)))[i] for i in range(len(string))])
print geExceltValue("AA")