Lists
In doing calculations, it is often convenient to collect together several objects, and treat them as a single entity. Lists give you a way to make collections of objects in the Wolfram Language. As you will see later, lists are very important and general structures in the Wolfram Language.
A list such as {3,5,1} is a collection of three objects. But in many ways, you can treat the whole list as a single object. You can, for example, do arithmetic on the whole list at once, or assign the whole list to be the value of a variable.
In[1]:= 1
✖
https://wolfram.com/xid/03mifq-ixz
Out[1]= 1
In[2]:= 2
✖
https://wolfram.com/xid/03mifq-krm
Out[2]= 2
This takes differences between corresponding elements in the two lists. The lists must be the same length:
In[3]:= 3
✖
https://wolfram.com/xid/03mifq-gqa
Out[3]= 3
In[4]:= 4
✖
https://wolfram.com/xid/03mifq-i11
Out[4]= 4
You can apply any of the mathematical functions in "Some Mathematical Functions" to whole lists:
In[5]:= 5
✖
https://wolfram.com/xid/03mifq-s6h
Out[5]= 5
In[6]:= 6
✖
https://wolfram.com/xid/03mifq-vxa
Out[6]= 6
In[7]:= 7
✖
https://wolfram.com/xid/03mifq-q0n
Out[7]= 7
We first encountered lists in "Making Lists of Objects" as a way of collecting numbers together. Here, we shall see many different ways to use lists. You will find that lists are some of the most flexible and powerful objects in the Wolfram Language. You will see that lists in the Wolfram Language represent generalizations of several standard concepts in mathematics and computer science.
At a basic level, what a Wolfram Language list essentially does is to provide a way for you to collect together several expressions of any kind.
In[1]:= 1
✖
https://wolfram.com/xid/03mifq-n6i
Out[1]= 1
In[2]:= 2
✖
https://wolfram.com/xid/03mifq-res
Out[2]= 2
In[3]:= 3
✖
https://wolfram.com/xid/03mifq-pus
Out[3]= 3
In[4]:= 4
✖
https://wolfram.com/xid/03mifq-srb
Out[4]= 4
The mathematical functions that are built into the Wolfram Language are mostly set up to be "listable" so that they act separately on each element of a list. This is, however, not true of all functions in the Wolfram Language. Unless you set it up specially, a new function f that you introduce will treat lists just as single objects. "Applying Functions to Parts of Expressions" and "Structural Operations" will describe how you can use Map and Thread to apply a function like this separately to each element in a list.
You can use lists as tables of values. You can generate the tables, for example, by evaluating an expression for a sequence of different parameter values.
In[1]:= 1
✖
https://wolfram.com/xid/03mifq-g5p
Out[1]= 1
In[2]:= 2
✖
https://wolfram.com/xid/03mifq-p5f
Out[2]= 2
In[3]:= 3
✖
https://wolfram.com/xid/03mifq-eb5
Out[3]= 3
In[4]:= 4
✖
https://wolfram.com/xid/03mifq-tji
Out[4]= 4
Table uses exactly the same iterator notation as the functions Sum and Product, which are discussed in "Sums and Products":
In[5]:= 5
✖
https://wolfram.com/xid/03mifq-v8z
Out[5]= 5
In[6]:= 6
✖
https://wolfram.com/xid/03mifq-t7q
Out[6]= 6
You can perform other operations on the lists you get from Table:
In[7]:= 7
✖
https://wolfram.com/xid/03mifq-s9y
Out[7]= 7
TableForm displays lists in a "tabular" format. Notice that both words in the name TableForm begin with capital letters:
In[8]:= 8
✖
https://wolfram.com/xid/03mifq-e1b
All the examples so far have been of tables obtained by varying a single parameter. You can also make tables that involve several parameters. These multidimensional tables are specified using the standard Wolfram Language iterator notation, discussed in "Sums and Products".
In[9]:= 9
✖
https://wolfram.com/xid/03mifq-bnm
Out[9]= 9
The table in this example is a list of lists. The elements of the outer list correspond to successive values of . The elements of each inner list correspond to successive values of , with fixed.
Sometimes you may want to generate a table by evaluating a particular expression many times, without incrementing any variables.
In[10]:= 10
✖
https://wolfram.com/xid/03mifq-gzy
Out[10]= 10
This gives a list of four pairs of numbers sampled from {1,2,3,4}. Table reevaluates RandomSample[{1,2,3,4},2] for each element in the list, so that you get four different samples:
In[19]:=19
✖
https://wolfram.com/xid/03mifq-s96
Out[19]=19
In[21]:=21
✖
https://wolfram.com/xid/03mifq-etal4f
Out[21]=21
In[30]:=30
✖
https://wolfram.com/xid/03mifq-83ep2
Out[30]=30
In[31]:=31
✖
https://wolfram.com/xid/03mifq-dbuf2u
Out[31]=31
You can use Table to generate arrays with any number of dimensions.
In[17]:= 17
✖
https://wolfram.com/xid/03mifq-s4j
Out[17]= 17
Table[f,{imax}] | give a list of imax values of f |
Table[f,{i,imax}] | give a list of the values of f as i runs from 1 to imax |
Table[f,{i,imin,imax}] | give a list of values with i running from imin to imax |
Table[f,{i,imin,imax,di}] | use steps of di |
Table[f,{i,imin,imax},{j,jmin,jmax},…] | generate a multidimensional table |
Table[f,{i,{i1,i2,…}] | give a list of the values of f as i successively takes the values i1, i2, … |
TableForm[list] | display a list in tabular form |
You can use the operations discussed in "Manipulating Elements of Lists" to extract elements of the table.
In[25]:=25
✖
https://wolfram.com/xid/03mifq-skww5
Out[25]=25
In[26]:=26
✖
https://wolfram.com/xid/03mifq-e40gon
Out[26]=26
In[27]:=27
✖
https://wolfram.com/xid/03mifq-6700i
Out[27]=27
In[23]:=23
✖
https://wolfram.com/xid/03mifq-qc0
Out[23]=23
In[13]:= 13
✖
https://wolfram.com/xid/03mifq-r3g
Out[13]= 13
In[14]:= 14
✖
https://wolfram.com/xid/03mifq-bb6
Out[14]= 14
In[15]:= 15
✖
https://wolfram.com/xid/03mifq-e6a
Out[15]= 15
In[16]:= 16
✖
https://wolfram.com/xid/03mifq-won
t[[i]] or Part[t,i] | give the i th sublist in t (also input as t〚i〛) |
t[[i;;j]] or Part[t,i;;j] | give a list of the parts i through j |
t[[{i1,i2,…}]] or Part[t,{i1,i2,…}] | give a list of the i1 th, i2 th, … parts of t |
t[[i,j,…]] or Part[t,i,j,…] | give the part of t corresponding to t[[i]][[j]]… |
As mentioned in "Manipulating Elements of Lists", you can think of lists in the Wolfram Language as being analogous to "arrays". Lists of lists are then like two‐dimensional arrays. When you lay them out in a tabular form, the two indices of each element are like its and coordinates.
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.
{a,b,c} | a list |
Part[list,i] or list[[i]] | the i th element of list (the first element is list[[1]]) |
Part[list,{i,j,…}] or list[[{i,j,…}]] | a list of the i th, j th, … elements of list |
Part[list,i;;j] | a list of the i th through j th elements of list |
In[1]:= 1
✖
https://wolfram.com/xid/03mifq-pod
Out[1]= 1
In[2]:= 2
✖
https://wolfram.com/xid/03mifq-ust
Out[2]= 2
In[3]:= 3
✖
https://wolfram.com/xid/03mifq-g1q
Out[3]= 3
In[4]:= 4
✖
https://wolfram.com/xid/03mifq-k3l
Out[4]= 4
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]].
Part[v,i] or v[[i]] | extract the i th element of a list |
Part[v,i]=value or v[[i]]=value | reset the i th element of a list |
In[5]:= 5
✖
https://wolfram.com/xid/03mifq-ekl
Out[5]= 5
In[6]:= 6
✖
https://wolfram.com/xid/03mifq-x2v
Out[6]= 6
In[7]:= 7
✖
https://wolfram.com/xid/03mifq-es1
Out[7]= 7
Vectors and matrices in the Wolfram Language are simply represented by lists and by lists of lists, respectively.
In[1]:=1
✖
https://wolfram.com/xid/03mifq-ut4
Out[1]=1
In[2]:=2
✖
https://wolfram.com/xid/03mifq-nhz
Out[2]=2
In[3]:=3
✖
https://wolfram.com/xid/03mifq-qay
Out[3]=3
In[4]:=4
✖
https://wolfram.com/xid/03mifq-v3e
Out[4]=4
In[5]:=5
✖
https://wolfram.com/xid/03mifq-dqw
Out[5]=5
In[6]:=6
✖
https://wolfram.com/xid/03mifq-gx1
Out[6]=6
In[7]:=7
✖
https://wolfram.com/xid/03mifq-dng
Out[7]=7
In[8]:=8
✖
https://wolfram.com/xid/03mifq-let
Out[8]=8
In[9]:=9
✖
https://wolfram.com/xid/03mifq-tth
Out[9]=9
In[10]:=10
✖
https://wolfram.com/xid/03mifq-i6b
Out[10]=10
In[11]:=11
✖
https://wolfram.com/xid/03mifq-p4l
Out[11]=11
Because of the way the Wolfram Language uses lists to represent vectors and matrices, you never have to distinguish between "row" and "column" vectors.
Table[f,{i,n}] | build a length‐n vector by evaluating f with i=1,2,…,n |
Array[a,n] | build a length‐n vector of the form {a[1],a[2],…} |
Range[n] | create the list {1,2,3,…,n} |
Range[n1,n2] | create the list {n1,n1+1,…,n2} |
Range[n1,n2,dn] | create the list {n1,n1+dn,…,n2} |
list[[i]] or Part[list,i] | give the i th element in the vector list |
Length[list] | give the number of elements in list |
c v | multiply a vector by a scalar |
a.b | dot product of two vectors |
Cross[a,b] |
cross product of two vectors (also input as
a×b
)
|
Norm[v] | Euclidean norm of a vector |
Table[f,{i,m},{j,n}] | build an m×n matrix by evaluating f with i ranging from 1 to m and j ranging from 1 to n |
Array[a,{m,n}] | build an m×n matrix with i,j th element a[i,j] |
IdentityMatrix[n] | generate an n×n identity matrix |
DiagonalMatrix[list] | generate a square matrix with the elements in list on the main diagonal |
list[[i]] or Part[list,i] | give the i th row in the matrix list |
list[[All,j]] or Part[list,All,j] | give the j th column in the matrix list |
list[[i,j]] or Part[list,i,j] | give the i,j th element in the matrix list |
Dimensions[list] | give the dimensions of a matrix represented by list |
Column[list] | display the elements of list in a column |
MatrixForm[list] | display list in matrix form |
In[12]:=12
✖
https://wolfram.com/xid/03mifq-hbk
Out[12]=12
In[13]:=13
✖
https://wolfram.com/xid/03mifq-szg
This gives a vector with symbolic elements. You can use this in deriving general formulas that are valid with any choice of vector components:
In[14]:=14
✖
https://wolfram.com/xid/03mifq-ht8
Out[14]=14
This gives a 3×2 matrix with symbolic elements. "Building Lists from Functions" discusses how you can produce other kinds of elements with Array:
In[15]:=15
✖
https://wolfram.com/xid/03mifq-gk6
Out[15]=15
In[16]:=16
✖
https://wolfram.com/xid/03mifq-txd
Out[16]=16
In[17]:=17
✖
https://wolfram.com/xid/03mifq-xza
Out[17]=17
c m | multiply a matrix by a scalar |
a.b | dot product of two matrices |
Inverse[m] | matrix inverse |
MatrixPower[m,n] | n th power of a matrix |
Det[m] | determinant |
Tr[m] | trace |
Transpose[m] | transpose |
Eigenvalues[m] | eigenvalues |
Eigenvectors[m] | eigenvectors |
In[18]:=18
✖
https://wolfram.com/xid/03mifq-wmd
Out[18]=18
In[19]:=19
✖
https://wolfram.com/xid/03mifq-qt2
Out[19]=19
In[20]:=20
✖
https://wolfram.com/xid/03mifq-wri
Out[20]=20
In[21]:=21
✖
https://wolfram.com/xid/03mifq-hto
Out[21]=21
In[22]:=22
✖
https://wolfram.com/xid/03mifq-lyu
Out[22]=22
In[23]:=23
✖
https://wolfram.com/xid/03mifq-ej6
Out[23]=23
In[24]:=24
✖
https://wolfram.com/xid/03mifq-qjw
Out[24]=24
In[25]:=25
✖
https://wolfram.com/xid/03mifq-pq8
Out[25]=25
Eigenvalues gives the eigenvalues of the matrix:
In[26]:=26
✖
https://wolfram.com/xid/03mifq-v4i
Out[26]=26
In[27]:=27
✖
https://wolfram.com/xid/03mifq-vxh
Out[27]=27
In[28]:=28
✖
https://wolfram.com/xid/03mifq-s28
Out[28]=28
"Linear Algebra in Wolfram Language" discusses many other matrix operations that are built into the Wolfram Language.
First[list] | the first element in list |
Last[list] | the last element |
Part[list,n] or list[[n]] | the n th element |
Part[list,-n] or list[[-n]] | the n th element from the end |
Part[list,m;;n] | elements m through n |
Part[list,{n1,n2,…}] or list[[{n1,n2,…}]] | |
the list of elements at positions n1, n2, … |
In[5]:=5
✖
https://wolfram.com/xid/03mifq-evg
Out[5]=5
In[2]:= 2
✖
https://wolfram.com/xid/03mifq-gho
Out[2]= 2
In[3]:= 3
✖
https://wolfram.com/xid/03mifq-jzu
Out[3]= 3
In[6]:=6
✖
https://wolfram.com/xid/03mifq-d2k5ks
Out[6]=6
In[4]:= 4
✖
https://wolfram.com/xid/03mifq-y4q
Out[4]= 4
Take[list,n] | the first n elements in list |
Take[list,-n] | the last n elements |
Take[list,{m,n}] | elements m through n (inclusive) |
Rest[list] | list with its first element dropped |
Drop[list,n] | list with its first n elements dropped |
Most[list] | list with its last element dropped |
Drop[list,-n] | list with its last n elements dropped |
Drop[list,{m,n}] | list with elements m through n dropped |
In[5]:= 5
✖
https://wolfram.com/xid/03mifq-g3n
Out[5]= 5
In[6]:= 6
✖
https://wolfram.com/xid/03mifq-lt
Out[6]= 6
In[7]:= 7
✖
https://wolfram.com/xid/03mifq-e6s
Out[7]= 7
In[8]:= 8
✖
https://wolfram.com/xid/03mifq-kdl
Out[8]= 8
In[9]:= 9
✖
https://wolfram.com/xid/03mifq-f46
Out[9]= 9
In[10]:= 10
✖
https://wolfram.com/xid/03mifq-kpj
Out[10]= 10
In[11]:= 11
✖
https://wolfram.com/xid/03mifq-sk
Out[11]= 11
"Manipulating Expressions like Lists" shows how all the functions here can be generalized to work not only on lists, but on any Wolfram Language expressions.
The functions here allow you to pick out pieces that occur at particular positions in lists. "Finding Expressions That Match a Pattern" shows how you can use functions like Select and Cases to pick out elements of lists based not on their positions, but instead on their properties.
Position[list,form] | the positions at which form occurs in list |
Count[list,form] | the number of times form appears as an element of list |
MemberQ[list,form] | test whether form is an element of list |
FreeQ[list,form] | test whether form occurs nowhere in list |
"Getting Pieces of Lists" discusses how to extract pieces of lists based on their positions or indices. The Wolfram System also has functions that search and test for elements of lists, based on the values of those elements.
In[1]:= 1
✖
https://wolfram.com/xid/03mifq-gye
Out[1]= 1
In[2]:= 2
✖
https://wolfram.com/xid/03mifq-noo
Out[2]= 2
In[3]:= 3
✖
https://wolfram.com/xid/03mifq-otk
Out[3]= 3
In[4]:= 4
✖
https://wolfram.com/xid/03mifq-srh
Out[4]= 4
In[5]:= 5
✖
https://wolfram.com/xid/03mifq-3i
Out[5]= 5
In[6]:= 6
✖
https://wolfram.com/xid/03mifq-iuw
Out[6]= 6
In[7]:= 7
✖
https://wolfram.com/xid/03mifq-ujg
Out[7]= 7
As discussed in "Finding Expressions That Match a Pattern", the functions Count and Position, as well as MemberQ and FreeQ, can be used not only to search for particular list elements, but also to search for classes of elements which match specific "patterns".
Prepend[list,element] | add element at the beginning of list |
Append[list,element] | add element at the end of list |
Insert[list,element,i] | insert element at position i in list |
Insert[list,element,-i] | insert at position i counting from the end of list |
Riffle[list,element] | interleave element between the entries of list |
Delete[list,i] | delete the element at position i in list |
ReplacePart[list,i->new] | replace the element at position i in list with new |
ReplacePart[list,{i,j}->new] | replace list[[i,j]] with new |
In[1]:= 1
✖
https://wolfram.com/xid/03mifq-o5e
Out[1]= 1
In[2]:= 2
✖
https://wolfram.com/xid/03mifq-snj
Out[2]= 2
In[1]:=1
✖
https://wolfram.com/xid/03mifq-b94rnd
Out[1]=1
In[3]:= 3
✖
https://wolfram.com/xid/03mifq-8m14y
Out[3]= 3
In[4]:= 4
✖
https://wolfram.com/xid/03mifq-x97
Out[4]= 4
Functions like ReplacePart take explicit lists and give you new lists. Sometimes, however, you may want to modify a list "in place", without explicitly generating a new list.
In[5]:= 5
✖
https://wolfram.com/xid/03mifq-pok
Out[5]= 5
In[6]:= 6
✖
https://wolfram.com/xid/03mifq-d38
Out[6]= 6
In[7]:= 7
✖
https://wolfram.com/xid/03mifq-uk2
Out[7]= 7
m[[i,j]]=new | replace the (i,j) th element of a matrix |
m[[i]]=new | replace the i th row |
m[[All,i]]=new | replace the i th column |
In[8]:= 8
✖
https://wolfram.com/xid/03mifq-ej3
Out[8]= 8
In[9]:= 9
✖
https://wolfram.com/xid/03mifq-bv4
Out[9]= 9
In[10]:= 10
✖
https://wolfram.com/xid/03mifq-d0j
Out[10]= 10
Join[list1,list2,…] | concatenate lists together |
Union[list1,list2,…] |
combine lists, removing repeated elements and sorting the result
|
Riffle[list1,list2] | interleave elements of list1 and list2 |
Join concatenates any number of lists together:
In[1]:= 1
✖
https://wolfram.com/xid/03mifq-o2r
Out[1]= 1
Union combines lists, keeping only distinct elements:
In[2]:= 2
✖
https://wolfram.com/xid/03mifq-wxs
Out[2]= 2
Riffle combines lists by interleaving their elements:
In[1]:=1
✖
https://wolfram.com/xid/03mifq-h71ulv
Out[1]=1
The Wolfram Language usually keeps the elements of a list in exactly the order you originally entered them. If you want to treat a Wolfram Language list like a mathematical set, however, you may want to ignore the order of elements in the list.
Union[list1,list2,…] | give a list of the distinct elements in the listi |
Intersection[list1,list2,…] | give a list of the elements that are common to all the listi |
Complement[universal,list1,…] | give a list of the elements that are in universal, but not in any of the listi |
Subsets[list] | give a list of all subsets of the elements in list |
DeleteDuplicates[list] | delete all duplicates from list |
Union gives the elements that occur in any of the lists:
In[1]:=1
✖
https://wolfram.com/xid/03mifq-oefmw0
Out[1]=1
Intersection gives only elements that occur in all the lists:
In[2]:=2
✖
https://wolfram.com/xid/03mifq-tws
Out[2]=2
Complement gives elements that occur in the first list, but not in any of the others:
In[3]:=3
✖
https://wolfram.com/xid/03mifq-gul
Out[3]=3
In[4]:=4
✖
https://wolfram.com/xid/03mifq-dfh
Out[4]=4
DeleteDuplicates deletes all duplicate elements from the list:
In[5]:=5
✖
https://wolfram.com/xid/03mifq-eij2mj
Out[5]=5
Sort[list] | sort the elements of list into a standard order |
Union[list] |
sort elements, removing any duplicates
|
Reverse[list] | reverse the order of elements in list |
RotateLeft[list,n] | rotate the elements of list n places to the left |
RotateRight[list,n] | rotate n places to the right |
This sorts the elements of a list into a standard order. In simple cases like this, the order is alphabetical or numerical:
In[1]:= 1
✖
https://wolfram.com/xid/03mifq-r6c
Out[1]= 1
In[2]:= 2
✖
https://wolfram.com/xid/03mifq-n1h
Out[2]= 2
In[3]:= 3
✖
https://wolfram.com/xid/03mifq-fsy
Out[3]= 3
You can rotate to the right by giving a negative displacement, or by using RotateRight:
In[4]:= 4
✖
https://wolfram.com/xid/03mifq-dwn
Out[4]= 4
PadLeft[list,len,x] | pad list on the left with x to make it length len |
PadRight[list,len,x] | pad list on the right |
In[5]:= 5
✖
https://wolfram.com/xid/03mifq-j2f
Out[5]= 5
Partition[list,n] | partition list into n‐element pieces |
Partition[list,n,d] | use offset d for successive pieces |
Split[list] | split list into pieces consisting of runs of identical elements |
SplitBy[list,f] | split list into runs of elements with identical values when f is applied |
Gather[list] | gather the elements of list into sublists of identical elements |
GatherBy[list,f] | gather the elements of list into sublists with identical values when f is applied |
In[1]:= 1
✖
https://wolfram.com/xid/03mifq-rwi
Out[1]= 1
In[2]:= 2
✖
https://wolfram.com/xid/03mifq-mo6
Out[2]= 2
In[3]:= 3
✖
https://wolfram.com/xid/03mifq-okm
Out[3]= 3
In[4]:= 4
✖
https://wolfram.com/xid/03mifq-ye9
Out[4]= 4
In[5]:= 5
✖
https://wolfram.com/xid/03mifq-wrw
Out[5]= 5
In[21]:=21
✖
https://wolfram.com/xid/03mifq-jfizmg
Out[21]=21
In[22]:=22
✖
https://wolfram.com/xid/03mifq-scvouc
Out[22]=22
In[27]:=27
✖
https://wolfram.com/xid/03mifq-ns5c14
Out[27]=27
In[25]:=25
✖
https://wolfram.com/xid/03mifq-h6dsae
Out[25]=25
Tuples[list,n] | generate all possible n‐tuples of elements from list |
Tuples[{list1,list2,…}] | generate all tuples whose i th element is from listi |
In[6]:= 6
✖
https://wolfram.com/xid/03mifq-lvi
Out[6]= 6
In[7]:= 7
✖
https://wolfram.com/xid/03mifq-q11
Out[7]= 7
Sort[list] | sort the elements of list into order |
Ordering[list] | the positions in list of the elements in Sort[list] |
Ordering[list,n] | the first n elements of Ordering[list] |
Ordering[list,-n] | the last n elements of Ordering[list] |
Permutations[list] | all possible orderings of list |
Min[list] | the smallest element in list |
Max[list] | the largest element in list |
In[50]:=50
✖
https://wolfram.com/xid/03mifq-i51
Out[50]=50
In[51]:=51
✖
https://wolfram.com/xid/03mifq-j06l7
Out[51]=51
This gives the positions of the elements of t, from the position of the smallest to that of the largest:
In[54]:=54
✖
https://wolfram.com/xid/03mifq-rrc
Out[54]=54
This is the same as Sort[t]:
In[55]:=55
✖
https://wolfram.com/xid/03mifq-oul
Out[55]=55
In[2]:= 2
✖
https://wolfram.com/xid/03mifq-s0i
Out[2]= 2
You will encounter nested lists if you use matrices or generate multidimensional arrays and tables. The Wolfram Language provides many functions for handling such lists.
Flatten[list] | flatten out all levels in list |
Flatten[list,n] | flatten out the top n levels in list |
Partition[list,{n1,n2,…}] | partition into blocks of size n1×n2×… |
Transpose[list] | interchange the top two levels of lists |
RotateLeft[list,{n1,n2,…}] | rotate successive levels by ni places |
PadLeft[list,{n1,n2,…}] | pad successive levels to be length ni |
In[1]:= 1
✖
https://wolfram.com/xid/03mifq-ntf
Out[1]= 1
In[2]:= 2
✖
https://wolfram.com/xid/03mifq-fyl
Out[2]= 2
There are many other operations you can perform on nested lists. More operations are discussed in "Manipulating Lists".