0
$\begingroup$

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

$\endgroup$
  • 2
    $\begingroup$ 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? $\endgroup$ – Jules Lamers Aug 22 '17 at 16:42
  • $\begingroup$ 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}} $\endgroup$ – Mudy Fa Aug 22 '17 at 16:49
  • $\begingroup$ What should happen if the 'third list' were {{10,11},{12,13},{20,21}} rather than {{10,10},{10,10},{20,20}}? $\endgroup$ – jjc385 Aug 22 '17 at 16:52
  • $\begingroup$ @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? $\endgroup$ – Jules Lamers Aug 22 '17 at 16:53
  • $\begingroup$ @jjc385 this doesnt matter... its only importan to combine them in the right direction $\endgroup$ – Mudy Fa Aug 22 '17 at 16:54
2
$\begingroup$

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 *)
$\endgroup$
  • $\begingroup$ Dont work, theres one coma mistake $\endgroup$ – Mudy Fa Aug 22 '17 at 17:54
  • $\begingroup$ @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. $\endgroup$ – Alan Aug 22 '17 at 18:29
  • $\begingroup$ No i Mean, there is a mistake in Fold, just try it!! $\endgroup$ – Mudy Fa Aug 23 '17 at 12:48
  • $\begingroup$ @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. $\endgroup$ – Alan Aug 23 '17 at 13:23
  • $\begingroup$ oh yes, it works, but there is something between, } and ] in the End of the Fold line something like this "^" $\endgroup$ – Mudy Fa Aug 23 '17 at 13:38
0
$\begingroup$
k = a[[3]][[All, 1]];
m = {Most@k};
n = {{Last@k}};

{Join[a[[1]], m, n], Join[a[[2]], m, n]}

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

$\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.