Track each distinct item as a dictionary key. For every occurrence, read the current count with a default of zero and add one. The example returns two for SQL and one for Python. Try predicting the result for an empty input.
- Section
- Topic learning
- Kind
- Worked example
- Subject
- Python
- Subtopic
- Dictionaries
- Difficulty
- Beginner
counts = {}
for skill in ["SQL", "Python", "SQL"]:
counts[skill] = counts.get(skill, 0) + 1
print(counts)