0
$\begingroup$
list = {{1, 2}, {2, 3}, {4, 5}, {6, 7}, {3, 1}, {5, 4}, {7, 8}, {8, 9},   {15, 0}, {6, 7}, {9, 7}, {4, 3}, {6, 3}};
list1 = {{a, b}, {d, e}, {t, r}};

I want to replace some elements of list by list1.

Final Result would be look like

finallist = {{1, 2}, {2, 3}, {4, 5}, {6, 7}, {3, 1},{a, b}, {d, e},{8, 9},{15, 0}, {6, 7}, {9, 7}, {4, 3}, {6, 3}};

Please help me, if possible

$\endgroup$
  • $\begingroup$ You could use something like Module[{r = list}, r[[6 ;; 7]] = list1[[1 ;; 2]]; r] $\endgroup$ – Carl Woll Aug 30 '18 at 15:53
  • $\begingroup$ Thank you but if your list is too big then how could I know position of elements. I do not like to count manually. Please Carl help me, I am new in Mathematica $\endgroup$ – Rony Saha Aug 30 '18 at 16:07
  • 3
    $\begingroup$ but what is the criterion of the replacement? in your list you could use list /. {{5, 4} -> list1[[1]], {7, 8} -> list1[[2]]}, but pls note that this would replace all the {5,4} and {7,8} elements of your list (even if in your example there is just one occurrence of each) $\endgroup$ – Fraccalo Aug 30 '18 at 16:11
  • 1
    $\begingroup$ Also, can you please edit your question explicitly specifying what you need (independence from element position etc.)? $\endgroup$ – Fraccalo Aug 30 '18 at 16:15
  • $\begingroup$ Fraccalo , suppose you have a list with 1000 elements then, how could you find any elements without counting manually? $\endgroup$ – Rony Saha Aug 30 '18 at 16:39
2
$\begingroup$

Rony, "how could you find any elements without counting manually". Is this what you are looking for?

Position[list, {5, 4}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.