Monday, November 4, 2019

IslandT: Summation of alphabet position with python

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.



from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...