title: Python Group By multiple keys in an array of dictionaries
body: <p>I have an array of dictionary like this in Python</p>
  
  <pre><code>{'district': u'd1', 'community': u'commu2', 'month': 8.0, 'county': u'c1', 'year': 2012.0, 'organization': u'org1'}
  {'district': u'd2', 'community': u'commu8', 'month': 9.0, 'county': u'c1', 'year': 2012.0, 'organization': u'org2'}
  {'district': u'd1', 'community': u'commu4', 'month': 9.0, 'county': u'c1', 'year': 2012.0, 'organization': u'org1'}
  {'district': u'd2', 'community': u'commu5', 'month': 8.0, 'county': u'c1', 'year': 2012.0, 'organization': u'org2'}
  {'district': u'd2', 'community': u'commu7', 'month': 9.0, 'county': u'c1', 'year': 2012.0, 'organization': u'org2'}
  {'district': u'd1', 'community': u'commu3', 'month': 9.0, 'county': u'c1', 'year': 2012.0, 'organization': u'org1'}
  {'district': u'd2', 'community': u'commu6', 'month': 8.0, 'county': u'c1', 'year': 2012.0, 'organization': u'org2'}
  {'district': u'd1', 'community': u'commu1', 'month': 8.0, 'county': u'c1', 'year': 2012.0, 'organization': u'org1'}
  </code></pre>
  
  <p>How can i group by multiple key values, like (district, month, year, organization) and generate a denormalized list like this ?</p>
  
  <pre><code>{'district': u'd1', 'organization': u'org1', 'month': 8.0, 'county': u'c1', 'year': 2012.0, 'community': ['commu1', 'commu2']}
  {'district': u'd1', 'organization': u'org1', 'month': 9.0, 'county': u'c1', 'year': 2012.0, 'community': ['commu3', 'commu4']}
  {'district': u'd2', 'organization': u'org2', 'month': 9.0, 'county': u'c1', 'year': 2012.0, 'community': ['commu5', 'commu6']}
  {'district': u'd2', 'organization': u'org2', 'month': 8.0, 'county': u'c1', 'year': 2012.0, 'community': ['commu7', 'commu8']}
  </code></pre>
  
  <p>EDIT: My database TABLE columns of interest are </p>
  
  <pre><code>DISTRICT, COMMUNITY, DATE, ORGANIZATION, COMMUNITY
  </code></pre>
  
  <p>I am using Django's ORM to fetch data in the format 1 as above, but i really need data in format 2</p>
  
  <p>My Django ORM fetch looks like this</p>
  
  <pre><code>list(ActivityReport.objects.all().
       values('date').\
      extra(select={'year': "EXTRACT(year FROM date)"}).\
      extra(select={'month': "EXTRACT(month FROM date)"}).\
       values('organization' ,'year','month', 'district', 'community'))
  </code></pre>
  
  <p>And my Django Model looks like this</p>
  
  <pre><code>class MyModel(models.Model):
      organization = models.CharField(max_length=200)
      district = models.CharField(max_length=200)
      community = models.CharField(max_length=200, null=True)
      date = models.DateField(default=datetime.date.today)
  </code></pre>