KeyErrors while generating a dict
<p>Below is the list of dict using trying to generate dict</p>

<pre><code>data = [
  {'date': datetime.date(2011, 8, 14), 'name': u'ab', 'total': 8},
  {'date': datetime.date(2011, 8, 15), 'name': u'ab', 'total': 8}, 
  {'date': datetime.date(2011, 8, 16), 'name': u'ab', 'total': 8}, 
  {'date': datetime.date(2011, 8, 17), 'name': u'ab', 'total': 8}, 
  {'date': datetime.date(2011, 8, 18), 'name': u'ab', 'total': 8},
  {'date': datetime.date(2011, 8, 19), 'name': u'ab', 'total': 8}, 
  {'date': datetime.date(2011, 8, 20), 'name': u'ab', 'total': 8}, 
  {'date': datetime.date(2011, 8, 21), 'name': u'ab', 'total': 8},
  {'date': datetime.date(2011, 8, 18), 'name': u'aj', 'total': 0},
  {'date': datetime.date(2011, 8, 14), 'name': u'ap', 'total': 8}, 
  {'date': datetime.date(2011, 8, 15), 'name': u'ap', 'total': 8},
  {'date': datetime.date(2011, 8, 16), 'name': u'ap', 'total': 8},
  {'date': datetime.date(2011, 8, 17), 'name': u'ap', 'total': 8},
  {'name': u'ab', 'l_total': 8, 'type': u'UP'}, 
  {'name': u'ab', 'l_total': 8, 'type': u'PL'},
  {'name': u'fk', 'l_total': 29, 'type': u''},
  {'name': u'jw', 'l_total': 1, 'type': u'PD'}, 
  {'name': u'uk', 'l_total': 16, 'type': u'UP'}, 
  {'name': u'sk', 'l_total': 24, 'type': u'PL'},
  {'name': u'ss', 'l_total': 8, 'type': u'PL'},
  {'name': u'sst', 'l_total': 8, 'type': u'PL'}]



results = collections.defaultdict(dict)

for fetch in data:
        user = fetch['name']
        hrs = fetch['total']
        row = results[user]
        new_y = fetch['type']
        row['new_y'] = fetch['l_total']
        row['user'] = user
        dt_string = str(fetch['date'])
        if dt_string in fetch and row[dt_string] != hr:
          raise Exception, "Contradiction: '%s' on '%s'" % (user, dt_string)
        row[dt_string] = hrs
        row.setdefault('Total', 0)
        row['Total'] += hrs
</code></pre>

<p>while generating below output</p>

<pre><code>{u'ap': {'Total': 32, 'user': u'ap', '2011-08-17': 8, 
         '2011-08-16': 8, '2011-08-15': 8, '2011-08-14': 8,
         'up': 8, 'PL':8})
</code></pre>

<p>Getting key error,any help really appreciate </p>

<p><strong>Note</strong> : Here you find two type of dicts one  {'date': datetime.date(2011, 8, 14), 'name': u'ab', 'total': 8}, and another is {'name': u'ab', 'total': 8, 'type': u'UP'},. difference between two is keys. in first dict you find <strong>date key</strong> and another dict <strong>type key</strong></p>
