This program uses the collections module in Python to count the frequency of elements in a list.
The collections.Counter function returns a dictionary where the keys are the elements in the list and the values are their respective frequencies. In this way, this program is counting the frequency of each element in the list.
import collections l = [10,30,50,10,20,60,20,60,40,40,50,50,30] print("Original List : ",l) f = collections.Counter(l) print("Frequency of the Elements: ",f)
Original List : [10, 30, 50, 10, 20, 60, 20, 60, 40, 40, 50, 50, 30] Frequency of the Elements: Counter({50: 3, 10: 2, 30: 2, 20: 2, 60: 2, 40: 2})
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions