write a program to generate a sequence and print the corresponding value of a key for the given string a key.
Input
A,AA,AB,AAA
OUTPUT
1,27,53,703
def convert(s):
n = len(s)
res = 0
for i in range(n-1, -1, -1):
res *= 26
res += ord(s[i]) - ord('A') + 1
return res
def main():
line = input()
L = [str(convert(s)) for s in line.split(',')]
res =','.join(L)
print(res)
main()
Comments
Leave a comment