MATHEMATICA HOW TO
How to | Combine and Rearrange Lists
Mathematica provides a complete data manipulation language with vast flexibility in rearranging lists with any number of elements in any kind of structure.
Set up a list of six integers with some duplicates (stored as
):
| In[1]:= |
| Out[1]= |
Sort the elements of the list
:
| In[2]:= |
| Out[2]= |
Use Union to sort
and remove any duplicates:
| In[3]:= |
| Out[3]= |
Note that unless you redefine
, it retains its original value:
| In[4]:= |
| Out[4]= |
| In[5]:= |
| Out[5]= |
| In[6]:= |
| Out[6]= |
| In[7]:= |
| Out[7]= |
Rotate the elements of
two places to the left:
| In[8]:= |
| Out[8]= |
Rotate the elements of
two places to the right:
| In[9]:= |
| Out[9]= |
Pad
on the left with
to get a list of length 10:
| In[10]:= |
| Out[10]= |
Partition the list
into sublists of length 2:
| In[11]:= |
| Out[11]= |
Partition the list
into sublists of length 2 with offset 1:
| In[12]:= |
| Out[12]= |
Split a list into runs of identical elements:
| In[13]:= |
| Out[13]= |
Flatten deletes inner braces in nested lists:
| In[14]:= |
| Out[14]= |
Join the elements of a set of lists:
| In[15]:= |
| Out[15]= |
