# Insert without extra brackets

I have a List1:

{{1, -1.1}, {2, -1}, {3, -0.9}, {4, 0}, {10, -0.4}}


and List2:

 {{2, -0.6}, {3, -0.6}}


and I would like insert the List2 to certain positions of the List1 like that:

 {{1, -1.1}, {2, -1}, {2, -0.6}, {3, -0.6}, {3, -0.9}, {4, 0}, {10, -0.4}}


But when I use Insert[List1,List2,3], I get extra brackets of the List2

{{1, -1.1}, {2, -1}, {{2, -0.6}, {3, -0.6}}, {3, -0.9}, {4, 0}, {10, -0.4}}


Is it possible do it without extra brackets?

• version 12.1 or later
list1 = {{1, -1.1}, {2, -1}, {3, -0.9}, {4, 0}, {10, -0.4}};
list2 = {{2, -0.6}, {3, -0.6}};
Insert[list1, Splice@list2, 3]


{{1, -1.1}, {2, -1}, {2, -0.6}, {3, -0.6}, {3, -0.9}, {4, 0}, {10, -0.4}}

• another way.
FlattenAt[Insert[list1, list2, 3], 3]

• Thanks, but Mathematica shows the error: Splice::string: String expected at position 1 in Splice[{{2,-0.6},{3,-0.6}}]. Oct 31, 2022 at 12:17
• @MamMam Needs version 12.1 or later. Another way Join[list1[[1 ;; 2]], list2, list1[[3 ;; -1]]] Oct 31, 2022 at 12:24
• For versions before 12.1, for simple cases (not this one), you may be able to replace the Splice@ with Sequence@@. Oct 31, 2022 at 14:20
• @GustavoDelfino I have test Sequence@@ befor I post the answer. It does not work. Oct 31, 2022 at 14:24

Using Sequence (for older versions of WL without Splice):

list1 = {{1, -1.1}, {2, -1}, {3, -0.9}, {4, 0}, {10, -0.4}};
list2 = {{2, -0.6}, {3, -0.6}};
Insert[list1, Inactive[Sequence] @@ list2, 3] // Activate

• A similar solution: Insert[list1, \[FormalG] @@ list2, 3] /. \[FormalG] -> Sequence (\[FormalG] can be replaced with any undefined variable) Oct 31, 2022 at 16:56
• Unevaluated[Sequence @@ list2]
– att
Oct 31, 2022 at 19:30

The theme of this answer ended up being : "playing with Sequence and MapAt"

• Using MapAt, Apply, Sequence and Insert:

MapAt[Apply[Sequence], Insert[list1, list2, 3], 3]

(* {{1, -1.1}, {2, -1}, {2, -0.6}, {3, -0.6}, {3, -0.9}, {4,
0}, {10, -0.4}}  *)

• Using MapAt, Sequence, Apply, Join, List and Function (no Insert):

MapAt[Sequence @@ list2~Join~{#} &, list1, 3]

(* {{1, -1.1}, {2, -1}, {2, -0.6}, {3, -0.6}, {3, -0.9}, {4,
0}, {10, -0.4}} *)

• Using MapAt, Construct, Sequence, Apply, and Function (no Insert):

MapAt[Construct[Sequence, Sequence @@ list2, #] &, list1, 3]

(* {{1, -1.1}, {2, -1}, {2, -0.6}, {3, -0.6}, {3, -0.9}, {4,
0}, {10, -0.4}} *)


but

 MapAt[Sequence[Sequence @@ list2, #] &, list1, 3]


EDIT

As mentioned by @att in the comments, the error is due to the fact that Function does not have the attribute SequenceHold. For workarounds for this issue see the answers here. Some of the workarounds from that question including the one by @att applied to this case are:

• Using MapAt, Sequence (x2), Apply, and Function(x2) (no Insert):

  MapAt[##&[Sequence @@ list2, #] &, list1, 3]

(* {{1, -1.1}, {2, -1}, {2, -0.6}, {3, -0.6}, {3, -0.9}, {4,
0}, {10, -0.4}}  *)

• Using MapAt, Sequence (x2), Apply(x2), and Function (no Insert):

 MapAt[Sequence @@ {Sequence @@ list2, #} &, list1, 3]

(* {{1, -1.1}, {2, -1}, {2, -0.6}, {3, -0.6}, {3, -0.9}, {4,
0}, {10, -0.4}} *)

• The last one fails because Function does not have the SequenceHold attribute. You can use ##& for the outer Sequence instead.
– att
Oct 31, 2022 at 19:50
• @att nice I saw the other answer where you used that technique. I supposes that it works as it defers the evaluation as with Sequence @@ {Sequence @@ list2, #} & Oct 31, 2022 at 20:32