This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)
 Documentation / Mathematica / Built-in Functions / Lists and Matrices / Structure Manipulation  /
Partition

  • Partition[ list , n ] partitions list into non-overlapping sublists of length n.
  • Partition[ list , n , d ] generates sublists with offset d.
  • Partition[ list , , , ... , , , ... ] partitions successive levels in list into length sublists with offsets .
  • Example: Partition[ a,b,c,d,e,f , 2].
  • All the sublists generated by Partition[ list , n , d ] are of length n. As a result, some elements at the end of list may 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.
  • If d is greater than n in Partition[ list , n , d ], then elements in the middle of list are skipped.
  • The object list need not have head List.
  • Partition[f[a,b,c,d], 2].
  • If list has length N, then Partition[ list , n , d ] yields Max[0, Floor[( N + d - n )/ d ]] sublists.
  • Partition[ list , , , ... , d ] uses offset d at each level.
  • See the Mathematica book: Section 1.8.10.
  • See also: Flatten, RotateLeft, Split.

    Further Examples

    This groups the elements of the original list in pairs; the is thrown away.

    In[1]:=

    Out[1]=

    This makes triples of elements, with each successive triple offset by just one element.

    In[2]:=

    Out[2]=