Need two functions scoreList and bestWord as well as testing

Need two functions scoreList and bestWord as well as testing them using the examples below. I am using Python.

Ultimately, there are two functions that we will be testing.

scoreList(Rack) takes as input a Rack which is a list of lower-case letters and returns a list of all of the words in the global Dictionary that can be made from those letters and the score for each one. Specifically, this function returns a list of lists, each of which contains a string that can be made from the Rack and its Scrabble score. Here are some examples using the tiny Dictionary above:

The order in which the words are presented is not important.

bestWord(Rack) takes as input a Rack as above and returns a list with two elements: the highest possible scoring word from that Rack followed by its score. If there are ties, they can be broken arbitrarily. Here is an example, again using the tiny Dictionary above:

scrabbleScores = [ [\"a\", 1], [\"b\", 3], [\"c\", 3], [\"d\", 2], [\"e\", 1], [\"f\", 4],
[\"g\", 2], [\"h\", 4], [\"i\", 1], [\"j\", 8], [\"k\", 5], [\"l\", 1],
[\"m\", 3], [\"n\", 1], [\"o\", 1], [\"p\", 3], [\"q\", 10], [\"r\", 1],
[\"s\", 1], [\"t\", 1], [\"u\", 1], [\"v\", 4], [\"w\", 4], [\"x\", 8],
[\"y\", 4], [\"z\", 10] ]

Dictionary = [\"a\", \"am\", \"at\", \"apple\", \"bat\", \"bar\", \"babble\", \"can\", \"foo\", \"spam\", \"spammy\", \"zzyzva\"]

Solution

tdict = [\"a\", \"am\", \"at\", \"apple\", \"bat\", \"bar\", \"babble\", \"can\", \"foo\", \"spam\", \"spammy\", \"zzyzva\"]
def scrabble(s):
   score = {\"a\": 1, \"c\": 3, \"b\": 3, \"e\": 1, \"d\": 2, \"g\": 2, \"f\": 4, \"i\": 1, \"h\": 4, \"k\": 5, \"j\": 8, \"m\": 3, \"l\": 1, \"o\": 1, \"n\": 1, \"q\": 10, \"p\": 3, \"s\": 1, \"r\": 1, \"u\": 1, \"t\": 1, \"w\": 4, \"v\": 4, \"y\": 4, \"x\": 8, \"z\": 10}
   total=0
   for letter in s:
       total = total + score[letter]
   return total
def scoreList(listt):
   ans = []
   for w in tdict:
       list1 = listt[:]
       hat = 0
       for c in w:
           if c not in list1:
               hat = 1
               break
           else:
               list1.remove(c)
       if(hat==0):
           ans.append([w,scrabble(w)])
   return ans
def bestWord(listt):
   l = scoreList(listt)
   m=0
   ans = []
   for a in l:
       if(a[1]>m):
           ans = a[:]
   return ans
print(scoreList([\"a\", \"s\", \"m\", \"o\", \"f\"]))
print(bestWord([\"a\", \"s\", \"m\", \"o\", \"f\"]))

Need two functions scoreList and bestWord as well as testing them using the examples below. I am using Python. Ultimately, there are two functions that we will

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site