<div class="gmail_quote">On Mon, Jul 26, 2010 at 11:50 PM, Vikram <span dir="ltr"><<a href="mailto:kpguy@rediffmail.com">kpguy@rediffmail.com</a>></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>
>>> x<br>
[['NM100', 1, 2], ['NM100', 3, 4], ['NM200', 5, 6]]<br>
>>> for i in x:<br>
... print i<br>
...<br>
['NM100', 1, 2]<br>
['NM100', 3, 4]<br>
['NM200', 5, 6]<br>
<br>
------<br>
how does one obtain list z such that<br>
<br>
z = [['NM100',1,2,3,4],['NM200',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="'courier new', monospace">collections.</font><a href="http://docs.python.org/library/collections.html#collections.defaultdict"><font class="Apple-style-span" face="'courier new', monospace">defaultdict</font></a><font class="Apple-style-span" face="'courier new', 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>