Is there a more pythonic way of converting excel-style columns to numbers (starting with 1)?
Working code up to two letters:
I made this one-liner:
colNameToNum = lambda cn: sum([((ord(cn[-1-pos]) - 64) * 26 ** pos) for pos in range(len(cn))])
It works by iterating through the letters in reverse order and multiplying by 1, 26, 26 * 26 etc, then summing the list. This method would be compatible with longer strings of letters, too.
I call it with:
print(colNameToNum("AA")) # 27
or
print(colNameToNum("XFD")) # the highest column allowed, I believe. Result = 16384