string list
Input
count_occurrences(['a', 'b', 'a'])
Output
{'a': 2, 'b': 1}
'a' appears twice and 'b' once; 'a' appears first so it appears first in the dict.
Full lesson preview
Count how many times each (hashable) item appears in an iterable and return a dictionary of counts.
Problem statement
Task
Examples
Input
count_occurrences(['a', 'b', 'a'])
Output
{'a': 2, 'b': 1}
'a' appears twice and 'b' once; 'a' appears first so it appears first in the dict.
Input format
Output format
Constraints
Samples
Input
count_occurrences([1, 2, 1, 3, 1])
Output
{1: 3, 2: 1, 3: 1}
1 appears three times; 2 and 3 appear once each.