Convert an excel or spreadsheet column letter to its number in Pythonic fashion

前端 未结 17 1233
夕颜
夕颜 2020-12-09 04:18

Is there a more pythonic way of converting excel-style columns to numbers (starting with 1)?

Working code up to two letters:



        
17条回答
  •  暖寄归人
    2020-12-09 04:46

    You could use this oneliner using comprehension and string that is fairly easy to use:

    sum([string.ascii_lowercase.index(c) + 26 ** i for i,c in enumerate(col_letters)])
    

提交回复
热议问题