There are thousands of functions in the Wolfram Language that work with lists.
You can do arithmetic with lists:
Compute the first 10 squares:
Plot the first 20 squares:
Sort sorts a list into order:
Length finds how long a list is:
Total gives the total from adding up a list:
Find the total of the numbers from 1 to 10:
Count counts the number of times something appears in a list.
Count the number of times a appears in the list:
It
’s often useful to be able to get individual elements of a list.
First gives the first element;
Last gives the last element.
Part gives the element at a particular position.
Pick out the first element of a list:
Pick out the last element:
Pick out element number 2:
Picking out the first element in a list you’ve sorted is the same as finding the minimum element:
If you have a number, like 5671, you can make a list of its digits using
IntegerDigits[5671].
Break a number into a list of digits:
Find the last digit:
Take lets you take a specified number of elements from the beginning of a list.
Take the first 3 elements from a list:
Take the first 10 digits of 2 to the power 100:
Drop drops elements from the beginning of a list.
{2,3,4}+{5,6,2} | | arithmetic on lists |
Sort[{5,7,1}] | | sort a list into order |
Length[{3,3}] | | length of a list (number of elements) |
Total[{1,1,2}] | | total of all elements in a list |
Count[{3,2,3},3] | | count occurrences of an element |
First[{2,3}] | | first element in a list |
Last[{6,7,8}] | | last element in a list |
Part[{3,1,4},2] | | particular part of a list, also written as {3, 1, 4}[[2]] |
Take[{6,4,3,1},2] | | take elements from the beginning of a list |
Drop[{6,4,3,1},2] | | drop elements from the beginning of a list |
IntegerDigits[1234] | | list of digits in a number |
5.1Make a list of the first 10 squares, in reverse order.
»
5.2Find the total of the first 10 squares.
»
5.3Make a plot of the first 10 squares, starting at 1.
»
5.5Use
Range and
+ to make a list of numbers from 10 to 20, inclusive.
»
5.6Make a combined list of the first 5 squares and cubes (numbers raised to the power 3), sorted into order.
»
5.7Find the number of digits in 2^128.
»
5.8Find the first digit of 2^32.
»
5.9Find the first 10 digits in 2^100.
»
5.10Find the largest digit that appears in 2^20.
»
5.11Find how many zeros appear in the digits of 2^1000.
»
5.13Make a line plot of the sequence of digits that appear in 2^128.
»
5.14Use
Take and
Drop to get the sequence 11 through 20 from
Range[100].
»
+5.1Make a list of the first 10 multiples of 3.
»
+5.2Make a list of the first 10 squares using only
Range and
Times.
»
+5.3Find the last digit of 2^37.
»
+5.4Find the second-to-last digit of 2^32.
»
+5.5Find the sum of all the digits of 3^126.
»
+5.6Make a pie chart of the sequence of digits that appear in 2^32.
»
+5.7Make a list of pie charts for the sequence of digits in 2^20, 2^40, 2^60.
»
Can one add lists of different lengths?
No.
{1, 2}+{1, 2, 3} won
’t work.
{1, 2, 0}+{1, 2, 3} would be fine, if that
’s what you mean.
Can there be a list with nothing in it?
Yes. {} is a list of length 0, with no elements. It’s usually called the null list or the empty list.
- IntegerDigits[5671] gives digits in base 10. IntegerDigits[5671, 2] gives digits in base 2. You can use any base you want. FromDigits[{5, 6, 7, 1}] reconstructs a number from its list of digits.
- Rest[list] gives all the elements of list after the first one. Most[list] gives all elements other than the last one.