Plays by region

Write codeMedium14 min

Your task

A podcast dashboard rolls listener plays up by region. Each play is recorded as a two-letter country code, and a reference table maps country codes to region names. Codes missing from the table are grouped under the literal region "other". Given the list of play country codes and the reference table, return a dictionary mapping each region name that received at least one play to its play count. For example, plays ["us", "de", "us", "xx"] with table {"us": "na", "de": "eu"} give {"na": 2, "eu": 1, "other": 1}. An empty play list returns an empty dictionary.

Examples

plays_by_region(codes: list[str], regions: dict[str,str]) -> dict[str,int]
Example 1
Inputplays_by_region(["us", "de", "us", "xx"], {"us": "na", "de": "eu"})
Output{"na": 2, "eu": 1, "other": 1}