Im trying to figure out how to compute a product of ordered pairs. So if I have two sets (1,3) and (2,4), I want to generate the following tuples (1,2), (1,4), (3,2), (3,4).
Now I wrote the following
def orderedproduct(set1, set2): op=[set()] for x in set1: for y in set2: op.add((x,y)) return op
Now, python has a problem with the second to last line because everytime I make two sets and run the program, it says that AttributeError: 'list' object has no attribute 'add'
Clearly something is breaking down with that line, but is it the line itself or is there something Im not seeing in the program?
Edit: Im not sure why my tabbing isnt working here but there should be 1 tab on the 2nd and 3rd line, 2 tabs on the 4th, 3 tabs on the 5th, 1 tab on the 6th.