如何重复列表中的元素n次?

How to repeat elements in list n times?

如何将列表中的每个元素重复n次并形成一个新列表?例如:

x=[1,2,3,4]
n=3

寻找:

[1,1,1,2,2,2,3,3,3,4,4,4]

repeatinner 参数是我要找的:

repeat([1, 2, 3, 4], inner = 3)

同时列出理解:

x = [1,2,3,4]
n = 3
result = [i for i in x for j in 1:n]