Varud

Socially Proximate Predictions

Flower

Archive for August, 2009

defaultdict to count items in Django

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:

>>> 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)]

>>>

This will give you the number of times each label appears in ExampleModel.objects.values(‘label’,'other_info’)

Boycott of Fox

One of the happy things I saw today is that the boycott of Fox (and in particular Glenn Beck) is actually picking up steam.  Companies like WalMart, UPS Stores, etc… have decided to join the campaign.

I don’t think you need to sign up here:

http://foxnewsboycott.com/

But perhaps just contact one or two companies with which you do business and let them know that you’re dissatisfied with their support of this low-brow vitriol.  And yes, it is their responsibility to vet their advertising outlets.

I remember seeing Glenn Beck when he was on CNN Airport while waiting to re-enter the country (yes, real Americans explore the world) as he was telling Arabs to get out of the country and accusing them en masse for all America’s ills.

Sadly, Glenn Beck reaches the most vulnerable people in our society – those with limited IQ.  We need to help them.