Python has a builtin module named "collections". This module provides some useful collection data types that we can use. Before using any of these data types we must import collections.
Within the collections module there is a data type called a counter. The counter will count every instance of a certain element from any collection data type.
We can create and use a new counter object like so:
The Counter object is similar to a dictionary. It will store as a key the letter and as the value the frequency of that key in the item it was passed.
Like dictionaries we can find the values associated with each key by typing the counter name and then the key enclosed in square brackets.
The Counter object has some useful methods that can be seen below.
.most_common(n): This will return the n most common items along with the amount of times they occur.
.subtract(collection): This will subtract the count of items from the collection passed from the Counter object.
.update(collection): This will add all of the counts of the collection to the Counter object.
.clear(): This will simply clear all of the counts from the Counter object.