[Baypiggies] nested list question

Jason Culverhouse jason at mischievous.org
Tue Jun 28 00:29:30 CEST 2011


On Jun 27, 2011, at 2:06 PM, Vikram K wrote:

> Suppose i have the following nested list:
> 
> >>> x
> [['19600894', '1', 'chr15_76136768', 'MISSENSE'], ['19600894', '2', 'chr15_76136768', 'MISSENSE'], ['18467762', '1', 'chr14_23354066', 'MISSENSE']]
> 
> 
> How do i obtain from nested list x (given above), the following nested list z:
> 
> >>> z
> [['chr15_76136768', 'MISSENSE'], ['chr14_23354066', 'MISSENSE']]
> 

How about:

	list(unique_everseen((y[2:4] for y in x), operator.itemgetter(0)))

or the whole nested list with just

	list(unique_everseen(x, operator.itemgetter(2)))

 where :

	unique_everseen is from 
	http://docs.python.org/library/itertools.html

If you data is already sorted by the key then 
	unique_justseen

might be more efficient?

Jason

> ------
> 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. 
> _______________________________________________
> Baypiggies mailing list
> Baypiggies at python.org
> To change your subscription options or unsubscribe:
> http://mail.python.org/mailman/listinfo/baypiggies

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20110627/566fec8b/attachment.html>


More information about the Baypiggies mailing list