Hi! I'm trying to solve this kind of scrabble quiz.
I'm a total newbie on Python and I know there are more efective solutions but I'd like to solve it with my skills at this moment.
My plan is to create a dictionary with supplied words [points] and run a loop that pass every letter from VALUE dict through every word. At the end of this loop, the value of every key in [points] is the sum of each letter value.
Finally I'll return the word with highest value in [points] dictionary.
Don't know if this is possible or I'm totally wrong with this plan. I'll appreciate any help with this.
This is my code at this moment:
VALUES = {'e': 1, 'a': 1, 'i': 1, 'o': 1, 'n': 1, 'r': 1,
't': 1, 'l': 1, 's': 1, 'u': 1, 'd': 2, 'g': 2,
'b': 3, 'c': 3, 'm': 3, 'p': 3, 'f': 4, 'h': 4,
'v': 4, 'w': 4, 'y': 4, 'k': 5, 'j': 8, 'x': 8,
'q': 10, 'z': 10}
def worth_of_words(words):
points = {words} #CREATE A DICTIONARY WITH WORDS AS KEY AND THEIR POINTS AS VALUE
for i in points: #For every word in "points" loop each letter from "VALUES", if letter is in word, add its value
for key in VALUES:
if key in i:
points[i] = points[i] + VALUES.get(key)
return max(points.value) #Return word with highest value in "points" dictionary
Created at: 2019/11/26 17:09; Updated at: 2019/11/28 00:51