I have a collections.defaultdict(int) that I\'m building to keep count of how many times a key shows up in a set of data. I later want to be able to sort it (obviously by turnin
from collections import defaultdict adict = defaultdict(int) adict['a'] += 1 adict['b'] += 3 adict['c'] += 5 adict['d'] += 2 for key, value in sorted(adict.items(), lambda a, b: cmp(a[1], b[1]), reverse=True): print "%r => %r" % (key, value) >>> 'c' => 5 'b' => 3 'd' => 2 'a' => 1