Counter

Learn about the Counter object for counting items in the Python dictionary.

We'll cover the following...

Overview

You’d think that algorithms could not get much simpler than using defaultdict(int). The I want to count specific instances in an iterable use case is common enough that the Python developers created a specific class for this exact purpose, simplifying things further. The previous code that counts characters in a string can easily be calculated in a single line:

Access this course and 1400+ top-rated courses and projects.