By defining a list of values, you can quickly plot a series of points, lines, or curves, or calculate statistical values such as mean, median, or standard deviation.
Watch the video for an introduction to lists, and read on to learn more.
Create a List
Create a list of values in between square brackets and separate elements with commas, such as \([1,3,4]\).
To generate a list of evenly spaced numbers, use an ellipsis. For example, \([1...10]\) represents the list of integers between \(1\) and \(10\) and \([1,3...11]\) represents the list of odd integers between \(1\) and \(11\).
You can use lists in any expression where you would use a single number, including the definition of a variable. This allows you to graph multiple lines or curves simultaneously.
If \(L\) is a list, you can refer to individual elements or subsets of elements by choosing the index of that element:
- Access the first element of \(L\) with \(L[1]\)
- Create a new list of the first, third, and fifth elements of \(L\) with \(L[1,3,5]\)
- \(L[1…5]\) accesses the first \(5\) elements
- Generate a list of elements of \(L\) from the third to the last with \(L[3…]\)
- Pull out the positive elements of \(L\) with \(L[L \gt 0]\)
- If \(M\) is another list, produce a list of elements from \(L\) at the indices specified by \(M\) with \(L[M]\)
See examples of each of these in the Index into a List graph.
Lists in Geometry
In the Geometry Tool, use lists to define parameters in transformations, create concentric circles, or make “string” art with gliders. Read more about gliders in our Sliders and Movable Points article.
Lists in 3D
In the 3D Graphing Calculator, you can use lists to plot multiple points and graph multiple curves or surfaces.
For instance, if you define a list \(L=[-4…4]\), then the expression \((L,L,L)\) will graph \(9\) points arranged in a diagonal line. Similarly, the expression \((L\sin(t), L\cos(t), L)\) will graph \(9\) circles, each with a radius and position on the \(z\)-axis defined by the values of \(L\).
List Operations
| Function | Inputs | Try typing... | Description |
|---|---|---|---|
| repeat | Two equal sized lists | repeat\(\mathbf{([1,5],[3,2])}\) |
Repeats each value in the first element according to the values of the corresponding second element. So, in the example, 1 is repeated three times, and 5 is repeated twice. Use the repeat function to create frequency tables. |
| join | Two or more lists | join\(\mathbf{([1,5],[3,2])}\) | Combines two or more lists into one list. |
| sort | One list | sort\(\mathbf{([5,1])}\) | Sorts the elements from smallest to largest. |
| shuffle | One list | shuffle\(\mathbf{([2,3,9])}\) |
Randomizes the elements in your list. When you add the shuffle function to the expression list, the Randomize icon |
| unique | One list | unique\(\mathbf{([1,5,5,10])}\) | Outputs a list of each element that is used in the list and removes any repeats. |
| for | Lists or intervals |
\(\mathbf{(a,b)}\) for \(\mathbf{a=[1,2], b=[1,2]}\) |
Test multiple values for a variable with either a list or an interval. |
List Comprehensions
You can create new lists based on existing lists using a list comprehension, which is written in the form: \(\left(x,y\right)\operatorname{for}x=\left[1...10\right],y=\left[1...10\right]\). This would create a list of the 100 points with integer coordinates \(1\le x \le 10\), \(1\le y \le 10\) and form a 10x10 grid of points.
A list comprehension consists of a body expression, which in this case \((x,y)\), and one or more input list variables. The resulting list is created by evaluating the body expression for each combination of values from the input lists.
Here are some more examples of list comprehensions and the lists they produce:
| Comprehension | Result |
|---|---|
| \(2k\operatorname{for}k=\left[1,2,3\right]\) | \( [2, 4, 6]\) |
| \(1\operatorname{for}k=\left[1...1000\right]\) | \([1, 1, 1, ...\)\((1000\) times)\(]\) |
| \(\operatorname{mean}\left(L.\operatorname{random}\left(10\right)\right)\operatorname{for}k=\left[1...100\right]\) | A list of \(100\) mean values, each calculated from \(10\) randomly selected values of list \(L\). |
Learn More
- Lists Walk Through
- Explore Lists Example Graph
- Functions
- Generalizing "for" Lists and Intervals
- Tables
Please write in with any questions or feedback to support@desmos.com.