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