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.

Leave your comment or provide your own solution below this post.

Please follow and like us:


  1. Hello,

    Here is another solution:
    In [15]: 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 [16]: words_to_marks(“python”)
    Out[16]: 98

Leave a Reply

Your email address will not be published. Required fields are marked *