<div class="gmail_quote">On Mon, Jul 26, 2010 at 11:50 PM, Vikram <span dir="ltr">&lt;<a href="mailto:kpguy@rediffmail.com">kpguy@rediffmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<br>
<br>
have the following:<br>
<br>
&gt;&gt;&gt; x<br>
[[&#39;NM100&#39;, 1, 2], [&#39;NM100&#39;, 3, 4], [&#39;NM200&#39;, 5, 6]]<br>
&gt;&gt;&gt; for i in x:<br>
... print i<br>
...<br>
[&#39;NM100&#39;, 1, 2]<br>
[&#39;NM100&#39;, 3, 4]<br>
[&#39;NM200&#39;, 5, 6]<br>
<br>
------<br>
how does one obtain list z such that<br>
<br>
z = [[&#39;NM100&#39;,1,2,3,4],[&#39;NM200&#39;,5,6]]<br>
<br><font class="Apple-style-span" face="Verdana" size="3"><span class="Apple-style-span" style="font-size: 11px; line-height: 15px;"><br></span></font></blockquote><div><br></div>Hint:   <font class="Apple-style-span" face="&#39;courier new&#39;, monospace">collections.</font><a href="http://docs.python.org/library/collections.html#collections.defaultdict"><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">defaultdict</font></a><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">(list)</font> is your friend here.  The first <a href="http://docs.python.org/library/collections.html#defaultdict-examples">example</a> from the docs is not far from your current problem. :)</div>