Thanks Jason. Could you (or someone else) suggest some approach for the following:<br><br>>>> x<br>[['19600894', '1', 'chr15_76136768', 'MISSENSE'],
['19600894', '2', 'chr15_76136768', 'MISSENSE'], ['18467762', '1',
'chr14_23354066', 'MISSENSE']]<br>
<br><br>How do i obtain from nested list x (given above), the following nested list z:<br><br>>>> z<br>[[19600894','1/2','chr15_76136768', 'MISSENSE', 'homozygous'], ['18467762', '1','chr14_23354066', 'MISSENSE', 'heterozygous']]<br>
<br>In list x, the first element is loci, second element is allele, third element is chromosome_positionofchange, fourth is type of change. Based on the value of the second and third element a new element has to be created --'homozygous' if both allele 1 and allele 2 have the change and 'heterozygous' if only one allele has the change.<br>
<font color="#000000"><font color="#144fae"><br></font></font><br><br><div class="gmail_quote">On Mon, Jun 27, 2011 at 6:29 PM, Jason Culverhouse <span dir="ltr"><<a href="mailto:jason@mischievous.org">jason@mischievous.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div style="word-wrap: break-word;"><div><div><div class="im"><div>On Jun 27, 2011, at 2:06 PM, Vikram K wrote:</div>
</div><div><div><div class="im"><br><blockquote type="cite">Suppose i have the following nested list:<br><br>>>> x<br>[['19600894', '1', 'chr15_76136768', 'MISSENSE'], ['19600894', '2', 'chr15_76136768', 'MISSENSE'], ['18467762', '1', 'chr14_23354066', 'MISSENSE']]<br>
<br><br>How do i obtain from nested list x (given above), the following nested list z:<br><br>>>> z<br>[['chr15_76136768', 'MISSENSE'], ['chr14_23354066', 'MISSENSE']]<br><font color="#000000"><font color="#144fae"><br>
</font></font></blockquote><div><br></div></div>How about:<div><span style="white-space: pre-wrap;"><br></span></div><div><span style="white-space: pre-wrap;">        </span>list(unique_everseen((y[2:4] for y in x), operator.itemgetter(0)))</div>
<div><br><div><div>or the whole nested list with just</div><div><span style="white-space: pre-wrap;"><br></span></div><span style="white-space: pre-wrap;">        </span>list(unique_everseen(x, operator.itemgetter(2)))<div><br></div>
<div> where :</div><div><br></div><div><span style="white-space: pre-wrap;">        </span>unique_everseen is from </div><div><span style="white-space: pre-wrap;">        </span><a href="http://docs.python.org/library/itertools.html" target="_blank">http://docs.python.org/library/itertools.html</a></div>
</div></div><div><br></div><div>If you data is already sorted by the key then </div><div><span style="white-space: pre-wrap;">        </span>unique_justseen</div><div><br></div><div>might be more efficient?</div><div><br></div><div>
Jason</div><div><br></div><blockquote type="cite"><div class="im">------<br>
In other words, if the third element of an element of x is the same, then i wish to combine it into a single element. <br></div>
_______________________________________________<br>Baypiggies mailing list<br><a href="mailto:Baypiggies@python.org" target="_blank">Baypiggies@python.org</a><br>To change your subscription options or unsubscribe:<br><a href="http://mail.python.org/mailman/listinfo/baypiggies" target="_blank">http://mail.python.org/mailman/listinfo/baypiggies</a></blockquote>
</div><br></div></div></div></div></blockquote></div><br>