# How to edit a list according to the other list? [duplicate]

Gday guys. This problem troubles me, and I hope you can help me solve it.

Say I have two random lists

L1={{2},{5},{1},{0},{4},{7},{8}}
L2={2,5,1,0,4,7,8}


and also a list

L3={3,5}


the list L3 means I don't want the elements in L1 at row 3 and 5, and elements in L2 at column 3 and 5. So I would like the results to come up like

resultsL1={{2},{5},{0},{7},{8}}
resultsL2={2,5,0,7,8}


I know how to use Delete or Drop to get rid of the row/column one by one, but I want an automatic way to do this job because the elements in L3 can have different elements and become any number in my original code. Thanks in advance!!

• Also see: (43785) Feb 5, 2015 at 10:41

There are several ways but the one I like is the following:

If L1 and L2 have same length then:

index = Complement[Range[Length[L1]], L3];
L1[[index]]
(*{{2}, {5}, {0}, {7}, {8}}*)
L2[[index]]
(*{2, 5, 0, 7, 8}*)

• Thank you Algohi. It works perfectly! Feb 5, 2015 at 3:40
• My pleasure :). Feb 5, 2015 at 3:47

Try this:

    Delete[L1, {#} & /@ L3]
Delete[L2, {#} & /@ L3]

(*  {{2}, {5}, {0}, {7}, {8}}  *)

(*   {2, 5, 0, 7, 8}          *)


Have fun!

• Nice! Thanks Alexi! Feb 6, 2015 at 6:47