list1 = {4, 6}
list2 = {1, 2}
ClearAll[f];
f = Join @@ MapThread[Table, {#2, List /@ #1}] &
f[list1, list2]
(* {1, 1, 1, 1, 2, 2, 2, 2, 2, 2} *)
f[{2, 3, 7}, {1, 2, 3}]
(* {1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3} *)
or
h = Join @@ (Table @@@ Transpose[{#2, List /@ #1}]) &
h[{2, 3, 7}, {1, 2, 3}]
(* {1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3} *)
or
g = Join @@ (ConstantArray @@@ Transpose[{#2, #1}])&
g2 = Inner[ConstantArray, #2, #1, Join] &
Timings:
bh = Inner[Table[#2, {#1}] &, #1, #2, Join] &; (* BobHanlon *)
{listA, listB} = RandomInteger[100, {2, 100000}];
(rs1 = bh[listA, listB]); // Timing
(* {0.265625, Null} *)
(rs2 = g[listA, listB]); // Timing
(* {0.062500, Null} *)
(rs3 = g2[listA, listB]); // Timing
(* {0.078125, Null} *)
(rs4 = h[listA, listB]); // Timing
(* {0.296875, Null} *)
(rs5 = f[listA, listB]); // Timing
(* {0.296875, Null} *)
rs1 == rs2 == rs3 == rs4 == rs5
(* True *)
Flatten @ MapThread[ ConstantArray[ #2 , #1 ] &, { list1 , list2 } ]
$\endgroup$Flatten@MapThread[ConstantArray[##] &, {list2, list1}]
$\endgroup$