title: Python dict question. How to group similar strings?
body: <pre><code>for i in names:
      dict[i] = {'firstname': name[i]['firstname'],
                 'lastname': name[i]['lastname']}
      print dict[0]['firstname'] # John
      print dict[0]['lastname'] # Doe
  
      # group similar lastnames, along with their firstnames
      # ...
  return render_to_response('index.html', dict)
  </code></pre>
  
  <p>I want to group names that end with similar last-names.
  For example, the output should be:</p>
  
  <pre><code>&lt;html&gt;
    &lt;body&gt;
      &lt;h1&gt; Doe &lt;/h1&gt;
      &lt;p&gt; John, Jason, Peter &lt;/p&gt;
  
      &lt;h1&gt; Avery &lt;/h1&gt;
      &lt;p&gt; Kelly, Brittany &lt;/p&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The 'h1' tags are supposed to contain the last-names and the 'p' tags the first-names.</p>
  
  <p>How should I do this?</p>