I need to find the frequency of elements in an unordered list
a = [1,1,1,1,2,2,2,2,3,3,4,5,5]
output->
b =
Data. Let's say we have a list:
fruits = ['banana', 'banana', 'apple', 'banana']
Solution. Then we can find out how many of each fruit we have in the list by doing this:
import numpy as np
(unique, counts) = np.unique(fruits, return_counts=True)
{x:y for x,y in zip(unique, counts)}
Output:
{'banana': 3, 'apple': 1}