I am writing a function in Python that gets two lists and returns a list of tuples with the Cartesian product of the input function. I can not use any function from the Python library.
Ex:
print(cartesiano([1,2],[11,22]))
# [(1, 11), (1,22), (2,11), (2, 22)]
My program is printing this: [(1, 11), (2, 22)]
. I can not fix the recursion.
def cartesiano(lista1,lista2):
def aux(l1,l2):
if l1==[] and l2==[]:
return []
return [(l1[0],l2[0])] +aux(l1[1:],l2[1:])
return aux(lista1, lista2)
I can not use repetition loops, as it is much more intuitive. It's a matter of functional programming, no ties, etc ...