### 6.3.7 Modifying the elements of a list

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

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

Input in Xcas mode, the index of the first element is 0:

subsop([0,1,2],'1=NULL')

| ⎡ ⎣ | 0,2 | ⎤ ⎦

Input in MuPAD or TI mode, the index of the first element is 1:

subsop([0,1,2],2=5)

or:

L:=[0,1,2];L[2]:=5

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

When using := to insert an element in a list, the list will be padded with zeros if necessary.

L:=[]

then:

L[3]:=5

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

In Maple mode the arguments are permuted and the index of the first element is 1.

subsop(2=5,[0,1,2])

or:

L:=[0,1,2];L[2]:=5

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