Guest User

Untitled

a guest
Feb 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. class A:
  2. def __init__(self, a, b):
  3. self.a = a
  4. self.b = b
  5. def __repr__(self):
  6. return "["+str(self.a)+","+str(self.b)+"]"
  7. def __eq__(self, oth):
  8. if self.a == oth.a and self.b == oth.b:
  9. return False
  10. return True
  11. def __ne__(self,oth):
  12. return not self == oth
  13. def __hash__(self):
  14. return self.a*1000+self.b
  15.  
  16. a = set()
  17. a.add(A(1,2))
  18. a.add(A(2,2))
  19. a.add(A(1,2))
  20.  
  21. for i in a:
  22. print i,hash(i)
  23. print a
Add Comment
Please, Sign In to add comment