[Tutor] nested list query
Alan Gauld
alan.gauld at btinternet.com
Tue Jun 28 00:54:02 CEST 2011
"Vikram K" <kpguy1975 at gmail.com> 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']]
Since it is not clear what exact algorithm you are following to derive
the second from the first I'll take the brute force sinplistic route:
[x[0][-2:],x[-1][-2:]]
Now, I'm pretty sure you have a more complex algorithm that just
using the first and last elements of the list, but since I don't know
what it is, this will have to do...
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list