Package sage :: Package combinat :: Module cartesian_product
[hide private]
[frames] | no frames]

Module cartesian_product

source code


Cartesian Products



Classes [hide private]
  CartesianProduct_iters
Functions [hide private]
 
CartesianProduct(*iters)
Returns the combinatorial class of the cartesian product of *iters.
source code
Function Details [hide private]

CartesianProduct(*iters)

source code 

Returns the combinatorial class of the cartesian
product of *iters.

EXAMPLES:
    sage: cp = CartesianProduct([1,2], [3,4]); cp
    Cartesian product of [1, 2], [3, 4]
    sage: cp.list()
    [[1, 3], [1, 4], [2, 3], [2, 4]]

  Note that if you have a generator-type object that is returned
  by a function, then you should use IterableFunctionCall class
  defined in sage.combinat.misc.

    sage: def a(): yield 1; yield 2
    sage: def b(): yield 'a'; yield 'b'
    sage: CartesianProduct(a(), b()).list()
    [[1, 'a'], [1, 'b']]
    sage: from sage.combinat.misc import IterableFunctionCall
    sage: CartesianProduct(IterableFunctionCall(a), IterableFunctionCall(b)).list()
    [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]