sub-list extraction, logical indexation
Terry Reedy
tjreedy at udel.edu
Tue Aug 18 20:08:20 EDT 2009
Pierre wrote:
> Hello Everyone,
>
> I would like to know if it is possible to extract a sub-list from a
> list ?
>
> typically if :
>
> L =[[1, 2, 3],[4, 5, 6],[3] ]
>
> How to extract easily the elements 0 and 2 of L in order to get :
>
> L2 =[[1, 2, 3],[3] ]
L2 = [L[0],L[2]]
>
> Moreover, I would like to know if it is possible to use logical
> indexation such that :
>
> index = [ True, False, True]
> L2 = L
use zip(index,L) in a for loop
>
> or usual indexation, something like
> index=[0, 2]
> L2 = L
#untried
L2=[]
for i in index
L2.append(L[i])
tjr
More information about the Python-list
mailing list