I need to find the frequency of elements in a list
a = [1,1,1,1,2,2,2,2,3,3,4,5,5]
output->
b = [4,4,2,1,2]
Also I want to remove the duplicates from a
a = [1,2,3,4,5]
I need to find the frequency of elements in a list
a = [1,1,1,1,2,2,2,2,3,3,4,5,5]
output->
b = [4,4,2,1,2]
Also I want to remove the duplicates from a
a = [1,2,3,4,5]
To remove duplicates and Maintain order:
In Python 2.7+, you could use collections.Counter to count items
You can use the in-built function provided in python
The above code automatically removes duplicates in a list and also prints the frequency of each element in original list and the list without duplicates.
Two birds for one shot ! X D
Counting the frequency of elements is probably best done with a dictionary:
To remove the duplicates, use a set: