How to insert / merge a list into another list?
A few options:
insertSequence1[x_, y_, n_] := Insert[x, Unevaluated[Sequence @@ y], n]
insertSequence2[x_, y_, n_] := Fold[Insert[##, n] &, x, Reverse@y]
insertSequence3[x_, y_, n_] := Insert[x, y, n] ~FlattenAt~ n
x = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}};
y = {{100, 100}, {200, 200}};
insertSequence1[x, y, 3]
insertSequence2[x, y, 3]
insertSequence3[x, y, 3]
{{1, 1}, {2, 2}, {100, 100}, {200, 200}, {3, 3}, {4, 4}, {5, 5}}
{{1, 1}, {2, 2}, {100, 100}, {200, 200}, {3, 3}, {4, 4}, {5, 5}}
{{1, 1}, {2, 2}, {100, 100}, {200, 200}, {3, 3}, {4, 4}, {5, 5}}
Just for variety:
l1 = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}};
l2 = {{100, 100}, {200, 200}};
Just using Join
:
f[x_, y_, n_] := Join[x[[1 ;; n - 1]], y, x[[n ;; -1]]]
So,
f[l1, l2, 3]
yields:
{{1, 1}, {2, 2}, {100, 100}, {200, 200}, {3, 3}, {4, 4}, {5, 5}}