Skip to Main Content

Excel Sheet Column Number

Problem URL:Excel Sheet Column Number

My Solution

Python

import string

def titleToNumber(columnTitle: str) -> int:
    str_list = string.ascii_uppercase[:26]

    column_num = 0
    letters = list(reversed(columnTitle))
    for index, letter in enumerate(letters):
        column_num += (str_list.index(letter)+1)*(26**index)

    return column_num

Let's Connect

Twitter GitHub LinkedIn