Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- If a = 1, b = 2, c = 3 ... z = 26
- Then l + o + v + e = 54
- and f + r + i + e + n + d + s + h + i + p = 108
- So friendship is twice stronger than love :-)
- The input will always be in lowercase and never be empty.
- '''
- alphabet = "abcdefghijklmnopqrstuvwxyz"
- def lexarithm(word):
- # Create the map/directory
- directory = {}
- counter = 0
- for i in range(0, len(alphabet)):
- counter += 1
- directory[alphabet[i]] = counter
- # print(directory)
- # Directory is ready, time for scanning the parameter "word"
- weights = []
- for i in range(0, len(word)):
- # For every character of the word, "word[i]"
- for key, value in directory.items():
- if word[i] == key:
- weights.append(value)
- break
- # The list "weights" contains the equivalent numbers matching with the letters of word
- sum = 0
- for i in range(0, len(weights)):
- sum += weights[i]
- return sum
- # MAIN FUNCTION
- print(lexarithm("love"))
- print(lexarithm("friendship"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement