Inserting an element into a list or a string: insert

### 5.40.10 Inserting an element into a list or a string: insert

The insert command inserts elements into a list or string.

- insert takes three arguments:
  - L, a list or a string.
  - i, an integer (the index).
  - x.
- insert(L,i,x) returns L with x inserted at index i and the necessary elements shifted to the right.

#### Examples.

- Input:
  insert([3,4,2],2,5)
  Output:

  ⎡ ⎣ | 3,4,5,2 | ⎤ ⎦

- Input:
  insert("342",2,"5")
  Output:

  "3452"

insert returns an error if the index is too large.
Input:

insert([3,4,2],4,5)

Output:

insert([3,4,2],4,5)
Error: Invalid dimension