One of the great things I discovered today is defaultdict(). This allows one to create dictionaries with a count for each item in a very compact and powerful way. Look at this:
This will give you the number of times each label appears in ExampleModel.objects.values('label','other_info')>>> for item in NoticeQueueBatchByUser.objects.filter(user=3).values('label','on_site'):... d[item['label']] += 1...>>> d.items()[(u'pagedisplay_violation', 4)]>>>
>>> from collections import defaultdict
>>> d = defaultdict(int)
>>> for item in ExampleModel.objects.values('label','other_info'):
... d[item['label']] += 1
...
>>> d.items()
[(u'key_1', 4),(u'another_key',2)]
>>>