This is documentation for Mathematica 6, which was
based on an earlier version of the Wolfram Language.
 Built-in Mathematica Symbol Tutorials »| See Also »| More About »

# Partition

 Partition[list, n]partitions list into non-overlapping sublists of length n. Partition[list, n, d]generates sublists with offset d. Partition[list, {n1, n2, ...}]partitions a nested list into blocks of size . Partition[list, {n1, n2, ...}, {d1, d2, ...}]uses offset di at level i in list. Partition[list, n, d, {kL, kR}]specifies that the first element of list should appear at position kL in the first sublist, and the last element of list should appear at or after position kR in the last sublist. If additional elements are needed, Partition fills them in by treating list as cyclic. Partition[list, n, d, {kL, kR}, x]pads if necessary by repeating the element x. Partition[list, n, d, {kL, kR}, {x1, x2, ...}]pads if necessary by cyclically repeating the elements xi. Partition[list, n, d, {kL, kR}, {}]uses no padding, and so can yield sublists of different lengths. Partition[list, nlist, dlist, {klistL, klistR}, padlist]specifies alignments and padding in a nested list.
• All the sublists generated by Partition[list, n, d] are of length n. Some elements at the end of list may therefore not appear in any sublist.
• All elements of list appear in the sublists generated by Partition[list, n, 1].
• If d is greater than n in Partition[list, n, d], then elements in the middle of list are skipped.  »
• Partition[list, n, d, {kL, kR}] effectively allows sublists that have overhangs that extend past the beginning or end of list.
• Common settings for {kL, kR} are:
 {1,-1} allow no overhangs {1,1} allow maximal overhang at the end {-1,-1} allow maximal overhang at the beginning {-1,1} allow maximal overhangs at both beginning and end
• Partition[list, n, d, {kL, kR}, padlist] effectively lays down repeated copies of padlist, then superimposes one copy of list on them, and partitions the result.  »
• Common settings for padlist are:
 x pad with repetitions of a single element {x1,x2,...} pad with cyclic repetitions of a sequence of elements list pad by treating list as cyclic (default) {} do no padding, potentially leaving sublists of different lengths
• If list has length s, then Partition[list, n, d] yields Max[0, Floor[(s+d-n)/d]] sublists.
• Partition[list, {n1, n2, ..., nr}] effectively replaces blocks of elements at level r in list by depth-r nested lists of neighboring elements.  »
• If no offsets are specified, the neighborhoods are adjacent and non-overlapping.
• Partition[list, {n1, n2, ...}, d] uses offset d at every level.
• Partition[list, nlist, dlist, {{kL1, kL2, ...}, {kR1, kR2, ...}}] specifies that element {1, 1, ...} of list should appear at position {kL1, kL2, ...} in the {1, 1, ...} block of the result, while element {-1, -1, ...} of list should appear at or after position {kR1, kR2, ...} in the {-1, -1, ...} block of the result.
• {kL, kR} is taken to be equivalent to {{kL, kL, ...}, {kR, kR, ...}}.
• {{k1, k2, ...}} is taken to be equivalent to {{k1, k2, ...}, {k1, k2, ...}}.
• Partition[list, {n1, n2, ..., nr}, klist, padlist] effectively makes a depth-r array of copies of padlist, then superimposes list on them, and partitions the result.
• If list has dimensions {s1, s2, ..., sr} then Partition[list, {n1, n2, ..., nr}] will have dimensions {q1, q2, ..., qr, n1, n2, ..., nr} where qi is given by Floor[si/ni].
• The object list need not have head List.  »
Partition into sublists of length 2:
 Out[1]=

Partition into sublists of length 3 with offset 1:
 Out[1]=

Partition a two-dimensional array into 2×2 blocks with offset 1:
 Out[1]=
 Scope   (16)
 Applications   (5)
New in 1 | Last modified in 5