Convert Letters to Numbers in Python Using list comprehension

36

Convert Letters to Numbers in Python using list comprehension
text = "itsmycode"

# elegant way using list comprehension
num_list = [ord(x) - 96 for x in text]

# print the converted letters as numbers in list
print("After converting letters to numbers", num_list)

Comments

Submit
0 Comments