python count the frequency of words in a list

from collections import Counter
counts = Counter(list1)

# Counter({'apple': 3, 'egg': 2, 'banana': 1})

Here is what the above code is Doing:
1. We created a list named list1.
2. We imported the Counter class from collections.
3. We created a Counter object named counts.
4. We passed the list list1 to the Counter object.
5. We printed the counts.

As you can see, the Counter object counts the number of occurrences of each element in the list.