# Select certain items from nested list

I have a list as follows:

lis1={{{a1,b1,c1,d1,e1},{a2,b2,c2,d2,e2}},
{{a3,b3,c3,d3,e3},{a4,b4,c4,d4,e4}}}


and would like to delete certain elements from it resp. pick certain elements to get a list as follows

lis2= {{{a1,c1,e1},{a2,c2,e2}},
{{a3,c3,e3},{a4,c4,e4}}}


My problem is that the data I would like to select are not in an consecutive order (otherwise I could use the Part function). Does anyone have an hint?

You actually can still use the Part function!

If you know the positions explicitly you can try:

lis1[[All, All, {1, 3, 5}]]


Or, if they follow a regular pattern:

lis1[[All, All, 1 ;; 5 ;; 2]]


Just learned from this answer by ciao that Downsample is made for this kind of task:

Downsample[#, {1, 2}] & /@ lis1
(* {{{a1, c1, e1}, {a2, c2, e2}}, {{a3, c3, e3}, {a4, c4, e4}}} *)


You can also use Take, Drop and Extract to get the same result:

Take[#, All, {1, -1, 2}] & /@ lis1
Drop[#, {}, {2, -1, 2}] & /@ lis1
First@Rest@Extract[lis1, {{0}, {;; , ;; , ;; ;; 2}}]


You can use arbitrary lists for Part specifications with Part and Extract. For example

#[[All, ;; , {1, 4, 5}]] &@lis1  (* or *)
First@Rest@Extract[lis1, {{0}, {All, ;; , {1, 4, 5}}}]


both give all rows and columns 1, 4 and 5 in all matrices in lis1:

(* {{{a1, d1, e1}, {a2, d2, e2}}, {{a3, d3, e3}, {a4, d4, e4}}} *)

• That only works for the specific example. OP said: "My problem is that the data I would like to select are not in an consecutive order (otherwise I could use the Part function)." – rm -rf May 2 '15 at 17:57
• @TheToad, i may be wrong, but i thought the quote meant the OP was not aware of the part specifications other than from;;to (since Part specs can be any list). – kglr May 2 '15 at 18:08
• @TheToad Even though the origins of the name change are clear, it will take (me) some time to get used to. Is it planned as permanent? – Leonid Shifrin May 2 '15 at 19:34
• @LeonidShifrin It was just for fun, mostly. I came across an image that I really liked and just went along with it :) How long I'll keep it, I don't know, lol. I've always treated online personas as ephemeral and have fun changing things around but I can see how it might be confusing for others, especially when there are some artifacts and other bread crumbs lying around :) I can revert if you'd like me to/find it confusing. – rm -rf May 4 '15 at 4:34
• @TheToad Oh no, by all means keep it as long as you want :). It's fun to everyone. I wasn't really serious. – Leonid Shifrin May 4 '15 at 9:00
lis1 /. b1|d1|b2|d2|b3|d3|b4|d4->Sequence[]