Mathematica 9 is now available

Documentation / Mathematica / The Mathematica Book / A Practical Introduction to Mathematica / Lists /

1.8.10 Grouping Together Elements of Lists

Functions for grouping together elements of lists.

Here is a list.

In[1]:= t = {a, b, c, d, e, f, g}

Out[1]=

This groups the elements of the list in pairs, throwing away the single element left at the end.

In[2]:= Partition[t, 2]

Out[2]=

This groups elements in triples. There is no overlap between the triples.

In[3]:= Partition[t, 3]

Out[3]=

This makes triples of elements, with each successive triple offset by just one element.

In[4]:= Partition[t, 3, 1]

Out[4]=

This splits up the list into runs of identical elements.

In[5]:= Split[{a, a, b, b, b, a, a, a, b}]

Out[5]=



Any questions about topics on this page? Click here to get an individual response.Buy NowMore Information
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.