Count Every Vote

Python for AIMedium+10 XP+10

Count Every Vote

A class voted for a trip. The votes come in as a list of place names.

Write count_votes(votes) that returns a dictionary of each place to how many votes it got.

  • Only places that got at least one vote appear in the dictionary.
  • An empty list gives an empty dictionary.
  • Start your dictionary empty: counts = {}.

Examples

votes = ['zoo', 'park', 'zoo']
returns {'zoo': 2, 'park': 1}
votes = ["museum", "zoo", "museum", "beach", "museum"]
returns {'museum': 3, 'zoo': 1, 'beach': 1}
votes = []
returns {}

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run