Slice a list of lists?

Andreas Waldenburger usenot at geekmail.INVALID
Wed Sep 8 21:17:08 CEST 2010


On Wed, 8 Sep 2010 15:11:51 -0400 Benjamin Kaplan
<benjamin.kaplan at case.edu> wrote:

> There is no simple way to get [1,4,7] because it is just a list of
> lists and not an actual matrix. You have to extract the elements
> yourself.
> 
> col = []
> for row in a:
>     col.append(row[0])
> 
> 
> You can do this in one line using a list comprehension:
> [ row[0] for row in a ]

I would suggest this (esp. the list comprehension version) over my
suggestion of zip(). WAAAYYYY more readable. Apparently I'm getting
rusty.

/W

-- 
INVALID? DE!




More information about the Python-list mailing list