Write a program to replace each string with an integer value in a given list of strings. The replacement integer value should be a sum of Ascci values of each character of the corresponding string.
list_rivers =["Ganges", "Godavari", "Brahmaputra", "Narmada","Yamuna", "Mahanadi", "Kaveri", "Tapti"]
I tried the following which is correct but I want to optimize the code.
list_rivers =["Ganges", "Godavari", "Brahmaputra", "Narmada", "Yamuna", "Mahanadi", "Kaveri", "Tapti"]
river = [] // empty list
for i in list_rivers:
num=0
for j in i:
num = num + ord(j)
river.append(num) // [597, 813, 1143, 692, 619, 787, 610, 514]
Can anyone help how to optimize the above code?
Thanks in advance.