title: How to Iterate through a Python defaultdict?
body: <p>I have a dictionary that looks like this.</p>
  
  <pre><code>defaultdict(&lt;type 'list'&gt;,
  {
   2012: [Counter({1: 1, 2: 1, 4: 1}), 3],
   2013: [Counter({4: 2, 12: 1, 5: 1, 6: 1}), 5],
   2014: [Counter({4: 3, 1: 1, 2: 1, 3: 1}), 6]}
  )
  </code></pre>
  
  <p>I am trying to iterate the through Counter dict. like this.</p>
  
  <pre><code>2012
  1 1
  2 1
  1 4
  3
  
  2013
  4 2
  12 1
  5 1
  6 1
  5
  </code></pre>
  
  <p>Here is the code I tried.</p>
  
  <pre><code>for key, value in d.iteritems():
      for k, v in value:
          print k, v
  </code></pre>
  
  <p>here is the error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:/test.py", line 42, in &lt;module&gt;
      for k, v in value:
  ValueError: too many values to unpack
  </code></pre>
  
  <p><strong>JINJA2 Solution:</strong></p>
  
  <pre><code>{% extends "base.html" %}
  {% block title %}Archive{% endblock %}
  {% block content %}
  
  &lt;dl&gt;
  {% for key, value in d.iteritems() %}
      &lt;dt&gt;&lt;a href="/{{ key }}"&gt;{{ key }}&lt;/a&gt; ({{ value[1] }})&lt;/dt&gt;
      {% for m, c in value[0].items() %}
         &lt;dd&gt;&lt;a href="/{{ key }}/{{ m }}"&gt;{{m|month_number}}&lt;/a&gt; ({{ c }})&lt;/a&gt;&lt;/dd&gt;
          {{ a }}
      {% endfor %}
  {% endfor %}
  &lt;/dl&gt;
  </code></pre>
  
  <p>{% endblock %}</p>