# Combine three lists in one with each other

I have a question about combining lists, I really tried it, but that's so hard for me. I'm a newbie.

I have this kind of a list:

a={{{2,3},{1,2},{3,5}},{{1,9},{1,5},{1,7}},{{10,10},{10,10},{20,20}}}

I need this kind of result:

res={{{2,3},{1,2},{3,5},{10,10},{20}},{{1,9},{1,5},{1,7},{10,10},{20}}}

My list can have 1000 of elements...

I would be thankful for your help

• Can you clarify what you want to achieve? For example, which of the input's 10s end up where in the desired output? Why should the {10,10},{20} in the output (twice) be grouped like that? Aug 22, 2017 at 16:42
• These are 3 lists, which i already combine: a1= {{2,3},{1,2},{3,5}},{{1,9},{1,5},{1,7}} a2={{10,10},{10,10}} a3={{20,20}} Aug 22, 2017 at 16:49
• What should happen if the 'third list' were {{10,11},{12,13},{20,21}} rather than {{10,10},{10,10},{20,20}}? Aug 22, 2017 at 16:52
• @MudyFa But your a1 is not a list (missing {}s?), and your question does not involve a2 and a3 but rather a2~Join~a3... Could you be a bit more precise? Aug 22, 2017 at 16:53
• @jjc385 this doesnt matter... its only importan to combine them in the right direction Aug 22, 2017 at 16:54

If I assume some typos in your presentation, this seems to be another question about how to append columns.

a1 = {{{2, 3}, {1, 2}, {3, 5}}, {{1, 9}, {1, 5}, {1, 7}}};
a2 = {{10, 10}, {10, 10}};
a3 = {{20}, {20}};
Fold[MapThread[Append, {#1, #2}] &, {a1, a2, a3}] (* appends all*)
% // MatrixForm  (* display nicely *)
• Dont work, theres one coma mistake Aug 22, 2017 at 17:54
• @MudyFa Please copy the entire code. It runs fine and produces your desired output. Note that my a3 is a correction of what you wrote: you said there were missing braces, so I added the braces needed for the format to make sense.
– Alan
Aug 22, 2017 at 18:29
• No i Mean, there is a mistake in Fold, just try it!! Aug 23, 2017 at 12:48
• @MudyFa You must have copied it wrong. It works as it should. If you are copying and pasting, that will sometimes lose end-of-lines. But the code is good.
– Alan
Aug 23, 2017 at 13:23
• oh yes, it works, but there is something between, } and ] in the End of the Fold line something like this "^" Aug 23, 2017 at 13:38
a = {{{2, 3}, {1, 2}, {3, 5}}, {{1, 9}, {1, 5}, {1, 7}}};
b = {{10, 10}, {10, 10}};
c = {{20}, {20}};

Another possibility

MapThread[Join[#1, {#2}, {#3}] &, {a, b, c}]

{{{2, 3}, {1, 2}, {3, 5}, {10, 10}, {20}}, {{1, 9}, {1, 5}, {1, 7}, {10, 10}, {20}}}

I have changed a few entries to visually differentiate where the items are landing after various operations. Matrix dimensions, however, remain the same as those from the accepted answer.

a = {{{2, 3}, {1, 2}, {3, 5}}, {{1, 9}, {1, 5}, {1, 7}}};
b = {{10, 20}, {30, 40}};
c = {{25}, {35}};

g1 = MapThread[Join@## &, {a, List /@ b, List /@ c}];

g2 = MapThread[Join, {a, List /@ b, List /@ c}];

g3 = MapThread[Catenate@{##} &, {a, List /@ b, List /@ c}];

g1 == g2 == g3

(* True *)

Result:

MatrixForm /@ {a, b, c, g1}

a = {{{2, 3}, {1, 2}, {3, 5}}, {{1, 9}, {1, 5}, {1, 7}}};
b = {{10, 10}, {10, 10}};
c = {{20}, {20}};