In this article, we will create a python function that will turn a string into a list, then return the sum of all the positions of the alphabets within that list based on a-z. a = 1, b =2 and so on, all the alphabets within that given string will be in lower case.

```def words_to_marks(s):

word_list = list(s)
a_z = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x','y', 'z']
sum = 0
for w in word_list:
sum += a_z.index(w) + 1
return sum
```

As you might guess, the above is just another question from CodeWars.

Dear readers, I am working hard to build this website just for Python from now onward, if you like this post, do share the post on any social media site, thank you.

1. Terry Reedy says:

This solution is O(n*n) whereas it is easy to write an O(n) solution in at least 2 ways.

2. Zachary Carciu says:

Hello,

Here is another solution:
“`
In : def words_to_marks(s):
…: letter_values = {letter: idx for idx, letter in enumerate(string.ascii_lowercase, 1)}
…: return sum(map(lambda x: letter_values[x], s))
…:

In : words_to_marks(“python”)
Out: 98
“`

1. IslandTropicalMen says:

nice