Here is my assignment:
Write a function inverse(rel) that takes a relation rel and returns the inverse relation of the relation rel. The inverse relation InvsetR of the relation R is dened as InvsetR = {(x, y) ∈ S × S |(y, x) ∈ R)}. Example:
inRelation({(1,1), (1,2), (2,3), (4,2)}) should return
{(1,1), (2,1), (3,2), (2,4)}
Here is my code:
def inverse(rel):
m=set()
for (x,y) in rel:
m.add(y,x)
return m
It says that I can add only one element. What can I do?