# concatenate a list with itself [duplicate]

I guess this is rather trivial. Given, e.g.,

L={1,2}


what are some common efficient ways to obtain

L
(*{1,2,1,2,1,2}*)


that is, the list concatenated three times with itself and obtained the new value. Thanks in advance.

• Catenate@ConstantArray[L, 3]? Apr 4, 2017 at 19:59
• closely related: 111863, 113327 related: 123743
– Kuba
Apr 4, 2017 at 20:01
• Outer[Times, ConstantArray[1, 5], {1, 2}] // Flatten Apr 4, 2017 at 20:05
• Is this close enough for a duplicate? Generate cyclic list from a list
– Kuba
Apr 4, 2017 at 20:10
• Thanks for the comments and suggested workarounds. I accept the duplicate nature of the question but just as a side remark. I wrote: ""I guess this is rather trivial". After having seen the responses I think I should not have written this phrase. I use Mathematica for several years and still I could not find anything to do it on my oown. I use Python for one month and I am able to simply write 3*L to get the desired output:-)! Apr 5, 2017 at 20:13

L = {1, 2};
ChartingpadList[L, 6]


{1,2,1,2,1,2}

Ps:Function ChartingCommonDumplistPad,Catenate,Flatten,ReplicateLayer,PaddingLayer,Table,ConstantArray,ArrayReshape and Array is relevant.Also ArrayPad from Kuba's comment here.

There is a dedicated function in R:

Needs["RLink"]
InstallR[]
REvaluate["rep(c(1,2),5)"]

(* {1., 2., 1., 2., 1., 2., 1., 2., 1., 2.} *)


Another possibility is to use length.out:

REvaluate["rep(c(1,2),length.out=5)"]

(* {1., 2., 1., 2., 1.} *)

• Upvote for trick..
– yode
Apr 4, 2017 at 20:18
• @yode It is related to your answer, using a dedicated function. Apr 4, 2017 at 20:19