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\']
the "old school way".
>>> alist=['a', 'a', 'b', 'b', 'b'] >>> d={} >>> for i in alist: ... if not d.has_key(i): d[i]=1 #also: if not i in d ... else: d[i]+=1 ... >>> d {'a': 2, 'b': 3}