Explore the latest version of An Elementary Introduction to the Wolfram Language »
3First Look at Lists
Lists are a basic way to collect things together in the Wolfram Language. {1,2,3} is a list of numbers. On their own, lists dont do anything; theyre just a way to store things. So if you give a list as input, itll just come back unchanged:
In[1]:=
Click for copyable input
Out[1]=
ListPlot is a function that makes a plot of a list of numbers.
Plot the list of numbers {1, 1, 2, 2, 3, 4, 4}:
In[2]:=
Click for copyable input
Out[2]=
Plot the list of numbers {10, 9, 8, 7, 3, 2, 1}:
In[3]:=
Click for copyable input
Out[3]=
Range is a function that makes a list of numbers.
Generate a list of numbers up to 10:
In[4]:=
Click for copyable input
Out[4]=
In[5]:=
Click for copyable input
Out[5]=
Reverse reverses the elements in a list.
Reverse the elements in a list:
In[6]:=
Click for copyable input
Out[6]=
Reverse what Range has generated:
In[7]:=
Click for copyable input
Out[7]=
Plot the reversed list:
In[8]:=
Click for copyable input
Out[8]=
Join joins lists together, making a single list as the result.
Join lists together:
In[9]:=
Click for copyable input
Out[9]=
In[10]:=
Click for copyable input
Out[10]=
Join two lists made by Range:
In[11]:=
Click for copyable input
Out[11]=
In[12]:=
Click for copyable input
Out[12]=
Reverse the list in the middle:
In[13]:=
Click for copyable input
Out[13]=
{1,2,3,4} list of elements
ListPlot[{1,2,3,4}] plot a list of numbers
Range[10] range of numbers
Reverse[{1,2,3}] reverse a list
Join[{4,5,6},{2,3,2}] join lists together
3.1Use Range to create the list {1, 2, 3, 4}»
Expected output:
Out[]=
3.2Make a list of numbers up to 100. »
Expected output:
Out[]=
3.3Use Range and Reverse to create {4, 3, 2, 1}»
Expected output:
Out[]=
3.4Make a list of numbers from 1 to 50 in reverse order. »
Expected output:
Out[]=
3.5Use Range, Reverse and Join to create {1, 2, 3, 4, 4, 3, 2, 1}»
Expected output:
Out[]=
3.6Plot a list that counts up from 1 to 100, then down to 1. »
Expected output:
Out[]=
3.7Use Range and RandomInteger to make a list with a random length up to 10. »
Sample expected output:
Out[]=
Expected output:
Out[]=
3.9Find a simpler form for Join[{1, 2}, Join[{3, 4}, {5}]]»
Expected output:
Out[]=
3.10Find a simpler form for Join[Range[10], Join[Range[10], Range[5]]]»
Expected output:
Out[]=
3.11Find a simpler form for Reverse[Join[Range[20], Reverse[Range[20]]]]»
Expected output:
Out[]=
+3.1Compute the reverse of the reverse of {1, 2, 3, 4}»
Expected output:
Out[]=
+3.2Use Range, Reverse and Join to create the list {1, 2, 3, 4, 5, 4, 3, 2, 1}»
Expected output:
Out[]=
+3.3Use Range, Reverse and Join to create {3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1}»
Expected output:
Out[]=
+3.4Plot the list of numbers {10, 11, 12, 13, 14}»
Expected output:
Out[]=
+3.5Find a simpler form for Join[Join[Range[10], Reverse[Range[10]]], Range[10]]»
Expected output:
Out[]=
Usually list 1 2 3. { and } are called braces or curly brackets. { is open brace and } is close brace.
Is a list a function?
Yes. {1, 2, 3} is List[1, 2, 3]. But unlike, say, Plus, the function List doesnt actually compute anything; it just comes back unchanged.
What is ListPlot plotting?
The values of successive list elements. The x value of each point gives the position in the list; the y value gives the value of that element.
How long can lists be?
As long as you want, until your computer runs out of memory.
 
Download Notebook Version
es