# How to merge lists? [closed]

For demonstrating purposes suppose I have the following.

j[-1, z_] := Cos[z];
j[1, z_] := Sin[z];
h[n_] := Table[j[(-1)^n, i π/2], {i, 5}];


What I want to do is simply combine the result I get from h and h

For h the output is

{0, -1, 0, 1, 0}


While for h the output is

{1, 0, -1, 0, 1}


I want to merge these two lists so I get

{0, -1, 0, 1, 0, 1, 0, -1, 0, 1}


How can I do it? Or is there perhaps an easier more elegant way to do it, like to tell my function h[n_] to do the case n=1 and n=2 straight away?

## closed as off-topic by Daniel Lichtblau, Yves Klett, WReach, Chris K, Mr.Wizard♦Oct 5 '17 at 3:30

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Daniel Lichtblau, Yves Klett, WReach, Chris K, Mr.Wizard
If this question can be reworded to fit the rules in the help center, please edit the question.

• Do you mean to Join them? – Szabolcs Oct 4 '17 at 14:23
• I get for your example: h={0.707107, 0., -0.707107, -1., -0.707107} and h={0.707107, 1., 0.707107, 0., -0.707107}? – mrz Oct 4 '17 at 14:54
• Yeah Join would have done it as well. @mrz Sorry it should have been π/2 and not π/4. – Turbotanten Oct 4 '17 at 15:40
• h~Join~h – corey979 Oct 4 '17 at 21:44

Join will do the trick:

j[-1, z_] := Cos[z];
j[1, z_] := Sin[z];
h[n_] := Table[j[(-1)^n, i π/2], {i, 5}];

Join[h, h]

(* {0, -1, 0, 1, 0, 1, 0, -1, 0, 1} *)


Okey I figured it out. Writing the following does the trick

j[-1, z_] := Cos[z];
j[1, z_] := Sin[z];
h = Table[j[(-1)^n, i π/2], {i, 5}, {n, 2}]

• To get the answer that you requested in the question, you need to change the order of summations and use Flatten, i.e., h = Table[j[(-1)^n, i \[Pi]/2], {n, 2}, {i, 5}] // Flatten – Bob Hanlon Oct 4 '17 at 16:14
j[-1, z_] := Cos[z];
j[1, z_] := Sin[z];
h = Table[j[(-1)^n, i π/2], {i, 5}, {n, 2}]

Flatten@{Take[h[[All, 1]]], Take[h[[All, 2]]]}

(* {0,-1,0,1,0,1,0,-1,0,1} *)