# Modifying the elements of a list: subsop

### 5.40.7 Modifying the elements of a list: subsop

The subsop command can be used to modify elements in a list.

- subsop takes two arguments:
  - L, a list.
  - i=value, an index and a new value.
- (In all but Maple mode).
  subsop(L,i=value) returns the list L with the value at index i replaced by value.
- (In Maple mode; the only difference is the order of the arguments).
  subsop(i=value,L) returns the list L with the value at index i replaced by value.

Remark: If the second argument is i=NULL, then the element at index i is removed from L.

You can also redefine elements (or define new elements, but not remove elements) with :=.

#### Examples.

- Input (in Xcas mode, the index of the first element is 0):
  subsop([0,1,2],1=5)
  or:
  L:=[0,1,2];L[1]:=5
  Output:

  ⎡ ⎣ | 0,5,2 | ⎤ ⎦

- Input (in Xcas mode, the index of the first element is 0):
  subsop([0,1,2],’1=NULL’)
  Output:

  ⎡ ⎣ | 0,2 | ⎤ ⎦

- Input (in Mupad TI mode, the index of the first element is 1):
  subsop([0,1,2],2=5)
  or:
  L:=[0,1,2];L[2]:=5
  Output:

  ⎡ ⎣ | 0,5,2 | ⎤ ⎦

- When using := to insert an element in a list, the list will be padded with 0s if necessary.
  Input:
  L:=[]
  then:
  L[3]:=5
  Output:

  ⎡ ⎣ | 0,0,0,5 | ⎤ ⎦

- In Maple mode the arguments are permuted and the index of the first element is 1.
  Input:
  subsop(2=5,[0,1,2])
  or:
  L:=[0,1,2];L[2]:=5
  Output:

  ⎡ ⎣ | 0,5,2 | ⎤ ⎦