Iterables

cartes

Returns the cartesian product of sequences as a generator.

Examples::
>>> from sympy.utilities.iterables import cartes
>>> list(cartes([1,2,3], 'abc'))
[[1, 'a'],
[1, 'b'],
[1, 'c'],
[2, 'a'],
[2, 'b'],
[2, 'c'],
[3, 'a'],
[3, 'b'],
[3, 'c']]

variations

variations(seq, n) Returns all the variations of the list of size n.

Has an optional third argument. Must be a boolean value and makes the method return the variations with repetition if set to True, or the variations without repetition if set to False.

Examples::
>>> from sympy.utilities.iterables import variations
>>> list(variations([1,2,3], 2))
[[1, 2], [1, 3], [2, 1], [2, 3], [3, 1], [3, 2]]
>>> list(variations([1,2,3], 2, True))
[[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]]

Table Of Contents

Previous topic

Codegen

Next topic

Development Tips: Comparisons in Python

This Page