Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Using reduce() with lambda solution in Clear category for Excel Column Number by Mysta
from functools import reduce
def column_number(name: str) -> int:
return reduce(lambda value, char: value * 26 + ord(char) - ord('A') + 1, name, 0)
"""
# More readable but not pythonic variant:
value: int = 0
for n in name:
value = value * 26 + ord(n) - ord('A') + 1
return value
"""
print("Example:")
print(column_number("AA"))
# These "asserts" are used for self-checking
assert column_number("A") == 1
assert column_number("Z") == 26
assert column_number("AB") == 28
assert column_number("ZY") == 701
print("The first mission is done! Click 'Check' to earn cool rewards!")
Dec. 21, 2025
Comments: