I have a list of names:
names = ['ALICE', 'BOB', 'ME']
Take 'A' as 1, 'B' as 2, 'C' as 3... The sum of 'ALICE' can be calculated with:
sum([ord(i) - ord('A') + 1 for i in 'ALICE']) // ALICE: 30, BOB: 19, ME: 18
Now, I want to calculate all the sum in names multiplied with index in the names, e.g., 30 * 1 + 19 * 2 + 18 * 3 = 122.
It's easy to do this like:
s = 0
for i in range(len(names)):
s += sum(([ord(j) - ord('A') + 1) * (i + 1) for j in names[i]])
print s
But I want to learn to do this in list generator style (in one line perhaps). How to do this?