Score a word from a letter point table

Write codeEasy10 min

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 letters a to z. 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 points scores 0.
  • An empty word scores 0.

Examples

word_score(word: str, points: dict[str,int]) -> int
Example 1
Inputword_score("cab", {"a": 1, "b": 3, "c": 3})
Output7
Example 2
Inputword_score("moon", {"m": 3, "o": 1})
Output5
Example 3
Inputword_score("", {})
Output0