pyPython Lab
Kirby's site
Dictionaries · 01 / 155 min

Count what you see

A dictionary turns a stream of items into counts. The key is the item, and the value is how many times you have seen it.

Your task

Write count_items(items). Return a dictionary counting each string. An empty list should return an empty dictionary.

Examplecount_items(["apple", "pear", "apple"]) → {"apple": 2, "pear": 1}
solution.pyPython 3
Your test results will appear here. Run with the button or ⌘/Ctrl + Enter.
Progress and drafts stay in this browser.