Operations on Lists

There are thousands of functions in the Wolfram Language that work with lists.

{1,2,3}+10

{1,1,2}*{1,2,3}

Range[10]^2

ListPlot[Range[20]^2]

Sort[{4,2,1,3,6}]

Length[{5,3,4,5,3,4,5}]

Total[{1,1,2,2}]

Total[Range[10]]

Count counts the number of times something appears in a list.

Count[{a,b,a,a,c,b,a},a]

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.

First[{7,6,5}]

Last[{7,6,5}]

Part[{7,6,5},2]

First[Sort[{6,7,1,2,4,5}]]

Min[{6,7,1,2,4,5}]

If you have a number, like 5671, you can make a list of its digits using IntegerDigits[5671].

IntegerDigits[1988]

Last[IntegerDigits[1988]]

Take lets you take a specified number of elements from the beginning of a list.

Take[{101,203,401,602,332,412},3]

Take[IntegerDigits[2^100],10]

Drop drops elements from the beginning of a list.

Drop[{101,203,401,602,332,412},3]

Make a list of the first 10 squares, in reverse order. »

Find the total of the first 10 squares. »

Make a plot of the first 10 squares, starting at 1. »

Use Sort, Join and Range to create {1,1,2,2,3,3,4,4}. »

Use Range and + to make a list of numbers from 10 to 20, inclusive. »

Make a combined list of the first 5 squares and cubes (numbers raised to the power 3), sorted into order. »

Find the number of digits in 2^128. »

Find the first digit of 2^32. »

Find the first 10 digits in 2^100. »

Find the largest digit that appears in 2^20. »

Find how many zeros appear in the digits of 2^1000. »

Use Part, Sort and IntegerDigits to find the second-smallest digit in 2^20. »

Make a line plot of the sequence of digits that appear in 2^128. »

Use Take and Drop to get the sequence 11 through 20 from Range[100]. »

Make a list of the first 10 multiples of 3. »

Make a list of the first 10 squares using only Range and Times. »

Find the last digit of 2^37. »

Find the second-to-last digit of 2^32. »

Find the sum of all the digits of 3^126. »

Make a pie chart of the sequence of digits that appear in 2^32. »

Make 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.

Tech Notes