def cartesian_product(list1, list2):
    """Returns the cartesian product of the lists."""
    ret = []
    for i in list1:
        ret.append([(i, j) for j in list2])
    return ret
Returns the cartesian product of the lists.
recipes/Python/149148_Finite_Arithmetic/recipe-149148.py