Manipulating Elements of Lists

Many of the most powerful list manipulation operations in the Wolfram Language treat whole lists as single objects. Sometimes, however, you need to pick out or set individual elements in a list.

You can refer to an element of a Wolfram Language list by giving its "index". The elements are numbered in order, starting at 1.

Operations on list elements.

This extracts the second element of the list:

{5,8,6,9}[[2]]

This extracts a list of elements:

{5,8,6,9}[[{3,1,3,2,4}]]

This assigns the value of v to be a list:

v={2,4,7}

You can extract elements of v:

v[[2]]

By assigning a variable to be a list, you can use Wolfram Language lists much like "arrays" in other computer languages. Thus, for example, you can reset an element of a list by assigning a value to v[[i]].

Array-like operations on lists.

Here is a list:

v={4,-1,8,7}

This resets the third element of the list:

v[[3]]=0

Now the list assigned to v has been modified:

v