I have a list which has repeating items and I want a list of the unique items with their frequency.
For example, I have [\'a\', \'a\', \'b\', \'b\', \'b\']
[\'a\', \'a\', \'b\', \'b\', \'b\']
If your items are grouped (i.e. similar items come together in a bunch), the most efficient method to use is itertools.groupby:
itertools.groupby
>>> [(g[0], len(list(g[1]))) for g in itertools.groupby(['a', 'a', 'b', 'b', 'b'])] [('a', 2), ('b', 3)]