Getting Pieces of Lists

Picking out elements of lists.

We will use this list for the examples:

t={a,b,c,d,e,f,g}

Here is the last element of t:

Last[t]

This gives the third element:

t[[3]]

This gives the list of elements 3 through 6:

t[[3;;6]]

This gives a list of the first and fourth elements:

t[[{1,4}]]

Picking out sequences in lists.

This gives the first three elements of the list t defined above:

Take[t,3]

This gives the last three elements:

Take[t,-3]

This gives elements 2 through 5 inclusive:

Take[t,{2,5}]

This gives elements 3 through 7 in steps of 2:

Take[t,{3,7,2}]

This gives t with the first element dropped:

Rest[t]

This gives t with its first three elements dropped:

Drop[t,3]

This gives t with only its third element dropped:

Drop[t,{3,3}]

"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 (RefLink[Select, paclet:ref/Select]) and (RefLink[Cases, paclet:ref/Cases]) to pick out elements of lists based not on their positions, but instead on their properties.