-2

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?)

Vector Lightning
  • 311
  • 1
  • 2
  • 9
  • possible duplicate of [Convert an excel or spreadsheet column letter to its number in Pythonic fashion](http://stackoverflow.com/questions/7261936/convert-an-excel-or-spreadsheet-column-letter-to-its-number-in-pythonic-fashion) – igavriil Mar 17 '15 at 16:26
  • ......... Who picks these type of names, and how'd you find that? There's no way that came up near the top in search when looking up "convert letters to numbers", I checked! – Vector Lightning Mar 17 '15 at 16:36

2 Answers2

1
def foo(c):
    return ord(c) - 64

foo('A')

1

foo('B')

2

off the top of my head :p

mephisto
  • 661
  • 1
  • 6
  • 14
  • Nice! Noticed that it needs to be caps-locked though... I'm a n00b, does the line "ord(thing.upper())" work? – Vector Lightning Mar 17 '15 at 16:39
  • sure, that would normalize it. "a".upper() => "A" and "A".upper() => "A". Basically, it will always result in an uppercase letter – mephisto Mar 17 '15 at 17:11
0
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")
PVNRT
  • 235
  • 1
  • 4
  • 14