Get count of each item in the List
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. 1 from collections import Counter And then create the Counter object with the list as argument. 1 2 numbers = [8, 8, 8, 1, 1, 9, 4, 4, 4, 4, 4, 4, 4] counter = Counter(numbers) You can use counter in various ways. ...