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$
8
  • $\begingroup$ You could use something like Module[{r = list}, r[[6 ;; 7]] = list1[[1 ;; 2]]; r] $\endgroup$
    – Carl Woll
    Aug 30, 2018 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, 2018 at 16:07
  • 4
    $\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, 2018 at 16:11
  • 2
    $\begingroup$ Also, can you please edit your question explicitly specifying what you need (independence from element position etc.)? $\endgroup$
    – Fraccalo
    Aug 30, 2018 at 16:15
  • 1
    $\begingroup$ @RonySaha you should really formalise what your problem is, and then edit the main question. At the moment, it's not clear whether you want to replace two specific items in the list, if you want to find their positions, if there is a pattern that you want to replace, a combination of the above or other. Please try to explain carefully what you want to achieve in the post above (use edit button) and we are happy to help you as possible $\endgroup$
    – Fraccalo
    Aug 31, 2018 at 7:58

1 Answer 1

2
$\begingroup$

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

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

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