How do I count unique values inside a list
values, counts = np.unique(words, return_counts=True)
More Detail
import numpy as npwords = ['b', 'a', 'a', 'c', 'c', 'c']values, counts = np.unique(words, return_counts=True)
The function numpy.unique returns sorted unique elements of the input list together with their counts:
['a', 'b', 'c'][2, 1, 3]