Score a word from a letter point table
Your task
A word game has a point value for each letter. A word scores the total of its letters' points.
Write word_score(word, points) that returns the score of word.
Input and output:
word: a string of up to 100,000 lowercase lettersatoz. It may be empty.points: a dictionary that maps single lowercase letters to integers between 0 and 100. It may be empty, and it may leave letters out.- Returns an integer.
Rules:
- Every occurrence of a letter counts, so a letter that appears 3 times scores 3 times.
- A letter missing from
pointsscores 0. - An empty word scores 0.
Examples
word_score(word: str, points: dict[str,int]) -> intExample 1
Input
word_score("cab", {"a": 1, "b": 3, "c": 3})Output
7Example 2
Input
word_score("moon", {"m": 3, "o": 1})Output
5Example 3
Input
word_score("", {})Output
0