Saturday 15 January 2011

function - Code golf! Is there a simple way to convert letters to numbers in Python? -


You know, like A = 1, B = 2 etc. If only I can make a long list of then, but maybe there is already a module for it.

If this works, the bonus is in "Excel coordinates" where AA = 27 continues. (Does this base number 26?)

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

foo ('a')

1

foo ('b')

2

Above my head: p


No comments:

Post a Comment