Help Please! When i test this function i get error \"object of type \'function\'
ID: 3921311 • Letter: H
Question
Help Please! When i test this function i get error "object of type 'function' has no len()", on line 35, if len(scoreList) >=1:
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:
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"]
def letterScore(letter, scoreList):
for i in scoreList:
if i[0] == letter: #if letter in score[0]
return i[1] #return value[0][1]
def wordScore(S, scoreList):
di = convertToDict(scoreList) #convert to dictionary
if (len(S) ==1): #base condition
return di[S[0]] #return score of first element
else:
return di[S[0]]+wordScore(S[1:],di) # if len of list is greater than
#1, call the function with list
#elements from 1 to remaining
def convertToDict(list):
if(type(list)==dict): # if type of passed element is dict
return list
di = {}
for i in list: # For each element in list
di[i[0]] = i[1] # add it to dict
return di
def scoreList(rack):
if len(scoreList) >=1:
return scoreList
for i in scoreList:
for j in dict:
L = [scoreList(rack-1)]
scoreList(rack-1)
return L
Explanation / Answer
Hey, Here you are defining a function "scoreList" with rack as a argument.
When you are calculating length of you have to pass "rack" to len.
But here you are doing with function instead of rack array variable.
Check with this, len(rack).
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.