So you want to count the frequency of an item in a collection? In Python 2.7 and 3.1 there’s a number of new high performance container datatypes, namely the Counter.
Example
1 2 3 4 | >>> a = ['a','a','a','b','b','c','c','c','c','c','c'] >>> from collections import Counter >>> Counter(a) Counter({'c': 6, 'a': 3, 'b': 2}) |
Pretty bad ass.