I want to write a function "product" which takes two lists a and b as parameters and returns a list with all pairs of elements from a and b as tuples.
For example, I have
a = ["a", "b"] and b = [1,2,3]
, and I want my output to be [("a", 1), ("a", 2), ("a", 3), ("b", 1), ("b", 2), ("b", 3)]
.
How do I do that?
I have tried with
def product(a, b):
return list(map(lambda x, y:(x,y), a, b))
a = ["a", "b"]
b = [1, 2, 3]
print(product(a, b))
but I get only [('a', 1), ('b', 2)] as an output. What do I need to change? I don't really understand what I need to add. I am new to programming in python so It's kind of a hard challenge in the beginning, so any help would be appreciated!