Partition
Partition[list, n] divides list into non-overlapping sublists of length n.
Partition[list, n, d] generates sublists with offset d.
Partition[list, 
,
, ...
] divides a nested list into blocks of size
.
Partition[list, 
,
, ...
, 
,
, ...
] uses offset
at level i in list.
Partition[list, n, d, 
, 
] specifies that the first element of list should appear at position
in the first sublist, and the last element of list should appear at or after position
in the last sublist. If additional elements are needed, Partition fills them in by treating list as cyclic.
Partition[list, n, d, 
, 
, x] pads if necessary by repeating the element x.
Partition[list, n, d, 
, 
, 
,
, ...
] pads if necessary by cyclically repeating the elements
.
Partition[list, n, d, 
, 
, 
] uses no padding, and so can yield sublists of different lengths.
Partition[list, nlist, dlist, 
, 
, padlist] specifies alignments and padding in a nested list.
Example: Partition[
a,b,c,d,e,f
, 2]
.
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.
The element e in Partition[
a,b,c,d,e
, 2]
is dropped.
Partition[
a,b,c,d,e
, 3, 1]
generates sublists with offset 1.
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, 1, d] picks out elements in the same way as Take[list,
1, -1, d
].
Partition[list, n, d, 
, 
] effectively allows sublists that have overhangs that extend past the beginning or end of list.
Partition[list, n, d, k] is equivalent to Partition[list, n, d,
k, k
].
Common settings for 
, 
are:
Example: Partition[
a,b,c,d
,2,1,
-1,1
]
.
Partition[list, n, d, 
, 
, 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:
Example: Partition[
a,b,c,d
,2,1,
-1,1
,
x,y
]
.
Partition[
a,b,c,d
,2,1,
-1,1
,
]
.
If list has length s, then Partition[list, n, d] yields Max[0, Floor[(s + d - n)/d]] sublists.
Partition[list, 
,
, ... , 
] 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, 
,
, ...
, d] uses offset d at every level.
Partition[list, nlist, dlist, 

,
, ...
, 

,
, ... 
]
specifies that element
1,1,...
of list should appear at position 
,
, ...
in the
1,1,...
block of the result, while element
-1,-1,...
of list should appear at or after position 
,
, ...
in the
-1,-1,...
block of the result.

, 
is taken to be equivalent to 

,
, ...
, 
,
, ... 
.


,
, ... 
is taken to be equivalent to 

,
, ...
, 
,
, ... 
.
Partition[list, 
,
, ... , 
, 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 
,
, ... , 
then Partition[list, 
,
, ... , 
] will have dimensions 
,
, ... ,
,
,
, ... , 
where
is given by Floor[
/
].
The object list need not have head List.
Partition[f[a,b,c,d], 2]
.
See The Mathematica Book on the web: Section 1.8.10.
See also: Flatten, RotateLeft, Split, Take.
Further Examples