Ask Your Question

Revision history [back]

The function cartesian_product might answer the question.

sage: A = [1, 2]
sage: B = [3, 4]
sage: for a, b in cartesian_product([A, B]):
....:     print(a, b)
....:
1 3
1 4
2 3
2 4

Or look into Python's itertools module as Max Alekseyev suggests.