Programming Riddle: How might you translate an Excel column name to a number?

前端 未结 28 1415
[愿得一人]
[愿得一人] 2020-11-29 22:26

I was recently asked in a job interview to resolve a programming puzzle that I thought it would be interesting to share. It\'s about translating Excel column letters to actu

28条回答
  •  天涯浪人
    2020-11-29 22:44

    In Python, without reduce:

    def transform(column_string):
        return sum((ascii_uppercase.index(letter)+1) * 26**position for position, letter in enumerate(column_string[::-1]))
    

提交回复
热议问题