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]
Python 2.7+ introduces Dictionary Comprehension. Building the dictionary from the list will get you the count as well as get rid of duplicates.
...
You can do this:
Output:
The first array is values, and the second array is the number of elements with these values.
So If you want to get just array with the numbers you should use this:
This approach can be tried if you don't want to use any library and keep it simple and short!
o/p