Scrabble_score Improvement


#1



https://www.codecademy.com/en/courses/python-intermediate-en-rCQKw/1/3?curriculum_id=4f89dab3d788890003000096


The code is correct, but I wanted to figure out a way to use lambda to shorten it, but I'm still trying to get the hang of using lambda. How could I implement lambda to take a char in word and sum the values from the corresponding dictionary key?


Some where in my code I have invalid syntax, but I can't really figure out where. The first set of code is the original, the second is the attempt at using lambda.


def scrabble_score(word):
    word_lc = word.lower()
    new_score = 0
    for char in word_lc:
        new_score += score[char]
    return new_score

def scrabble_score(word):
    new_score = 0
    new_score = sum(map(lambda char: for char in word.lower() in score[char]))
    return new_score


#2

The code in your lambda expression is more like a list comprehension.

The map function iterates over the supplied sequence and maps the score of each char. Below is the Python 3 approach which requires list().

return sum(list(map(lambda c: score[c], word.lower())))

Here is the list comprehension approach...

return sum([score[c] for c in word.lower()])

#4