Iterables

cartes

Returns the cartesian product of two sequences

Examples::
>>> from sympy.utilities.iterables import cartes
>>> cartes([1,2,3], ['a', 'b', 'c'])
[[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
>>> variations([1,2,3], 2)
[[1, 2], [1, 3], [2, 1], [2, 3], [3, 1], [3, 2]]
>>> 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

Utilities

Next topic

Development Tips: Comparisons in Python

This Page