Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica >

Rearranging Nested Lists

You will encounter nested lists if you use matrices or generate multidimensional arrays and tables. Mathematica provides many functions for handling such lists.
Flatten[list]flatten out all levels in list
Flatten[list,n]flatten out the top n levels in list
Partition[list,{n1,n2,...}]partition into blocks of size n1×n2×...
Transpose[list]interchange the top two levels of lists
RotateLeft[list,{n1,n2,...}]rotate successive levels by ni places
PadLeft[list,{n1,n2,...}]pad successive levels to be length ni

A few functions for rearranging nested lists.

This "flattens out" sublists. You can think of it as effectively just removing all inner braces.
In[1]:=
Click for copyable input
Out[1]=
This flattens out only one level of sublists.
In[2]:=
Click for copyable input
Out[2]=
There are many other operations you can perform on nested lists. We will discuss more of them in "Manipulating Lists".
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team