From this array
a=[apple , lemon , apple , apple , lemon]
I want to create a dictionary like this
my_dictionary = {'apple':3 , 'lemon':2}
>>> from collections import counter
>>> a=['apple' , 'lemon' , 'apple' , 'apple' , 'lemon']
>>> Counter(a)
Counter({'apple': 3, 'lemon': 2})
A Counter is a dict subclass for counting hashable objects. It is an unordered collection where elements are stored as dictionary keys and their counts are stored as dictionary values. Counts are allowed to be any integer value including zero or negative counts. The Counter class is similar to bags or multisets in other languages.