Tuples

Tuples[list,n]

generates a list of all possible ntuples of elements from list.

Tuples[{list1,list2,}]

generates a list of all possible tuples whose i^(th) element is from listi.

Details

  • The elements of list are treated as distinct, so that Tuples[list,n] for a list of length k gives output of length kn.
  • The order of elements in Tuples[list,n] is based on the order of elements in list, so that Tuples[{a1,,ak},n] gives {{a_(1),a_(1),...,a_(1)},{a_(1),a_(1),...,a_(2)},...,{a_(k),a_(k),...,a_(k)}}.
  • Tuples[list,{n1,n2,}] generates a list of all possible n_(1)n_(2) arrays of elements in list.
  • The object list need not have head List. The head at each level in the arrays generated by Tuples will be the same as the head of list.

Examples

open allclose all

Basic Examples  (3)

All possible 3-tuples of 0 and 1:

In[1]:=
Click for copyable input
Out[1]=

The first element given is always picked first:

In[1]:=
Click for copyable input
Out[1]=

All ways of picking one element from each list:

In[1]:=
Click for copyable input
Out[1]=

Generalizations & Extensions  (3)

Applications  (8)

Properties & Relations  (3)

Possible Issues  (1)

Neat Examples  (6)

See Also

Outer  Array  IntegerDigits  Permutations  Subsets  Groupings  Distribute

Tutorials

Introduced in 2004
(5.1)