5
$\begingroup$

I have two lists:

list1 = {{{x1,x2},{x3,x4}}, {{x5,x6},{x7,x8}}};
list2 = {{{x9,x10},{x11,x12}}, {{x13,x14},{x15,x16}}}

I need to join them to get one list:

 {{{x1,x2},{x3,x4},{x9,x10},{x11,x12}}, {{x5,x6},{x7,x8},{x13,x14},{x15,x16}}}

There is a Join[] function that seem like a good choice to solve this problem but I can't apply it in a right way to get the appropriate result. What can I do?

$\endgroup$

3 Answers 3

9
$\begingroup$

You can use Join with level specification 2:

Join[list1, list2, 2]

{{{x1, x2}, {x3, x4}, {x9, x10}, {x11, x12}}, {{x5, x6}, {x7, x8}, {x13, x14}, {x15, x16}}}

$\endgroup$
6
$\begingroup$
MapThread[Join, {list1, list2}]

{{{x1, x2}, {x3, x4}, {x9, x10}, {x11, x12}}, {{x5, x6}, {x7, x8}, {x13, x14}, {x15, x16}}}

$\endgroup$
1
  • $\begingroup$ I think this works in older versions of Mathematica (pre V10) $\endgroup$
    – mikado
    Commented Dec 8, 2019 at 15:00
4
$\begingroup$
Flatten[{list1, list2}, {2, 1, 3}]

{{x1, x2}, {x3, x4}, {x9, x10}, {x11, x12}, {x5, x6}, {x7, x8}, {x13, x14}, {x15, x16}}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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