2
$\begingroup$

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!!

$\endgroup$
1
  • $\begingroup$ Also see: (43785) $\endgroup$ Commented Feb 5, 2015 at 10:41

2 Answers 2

2
$\begingroup$

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}*) 
$\endgroup$
2
  • $\begingroup$ Thank you Algohi. It works perfectly! $\endgroup$ Commented Feb 5, 2015 at 3:40
  • $\begingroup$ My pleasure :). $\endgroup$ Commented Feb 5, 2015 at 3:47
2
$\begingroup$

Try this:

 Delete[L1, {#} & /@ L3] Delete[L2, {#} & /@ L3] (* {{2}, {5}, {0}, {7}, {8}} *) (* {2, 5, 0, 7, 8} *) 

Have fun!

$\endgroup$
1
  • $\begingroup$ Nice! Thanks Alexi! $\endgroup$ Commented Feb 6, 2015 at 6:47

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.