How to | Combine and Rearrange Lists
The Wolfram System 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 v):
v = {3, 1, 3, 2, 5, 4}Sort the elements of the list v:
Sort[v]Use Union to sort v and remove any duplicates:
Union[v]Note that unless you redefine v, it retains its original value:
vv = Union[v]vReverse[v]Rotate the elements of v two places to the left:
RotateLeft[v, 2]Rotate the elements of v two places to the right:
RotateRight[v, 2]Pad v on the left with x to get a list of length 10:
PadLeft[v, 10, x]Partition the list v into sublists of length 2:
Partition[v, 2]Partition the list v into sublists of length 2 with offset 1:
Partition[v, 2, 1]Split a list into runs of identical elements:
Split[{1, 4, 1, 1, 1, 2, 2, 3, 3}]Flatten deletes inner braces in nested lists:
Flatten[{{a, b}, {c, {d}, e}, {f, {g, h}}}]Join the elements of a set of lists:
Join[{a, b}, {c, d, e}, {f, g, h}]