Sometimes you need the count of each item in the List. Python comes with a handy tool in the collections module exactly for this task.
First you have to import the Counter.
|
|
And then create the Counter object with the list as argument.
|
|
You can use counter in various ways.
|
|
You can get a count of specific item.
|
|
Counter object also comes with a very handy method to return a most common item. You can pass an argument to specify if you want just the most common item or more.
|
|