Skip to content

Instantly share code, notes, and snippets.

@yuroyoro
Created May 8, 2009 04:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuroyoro/108617 to your computer and use it in GitHub Desktop.
Save yuroyoro/108617 to your computer and use it in GitHub Desktop.
class Bar(object):
def __init__(self,p1,p2):
self.p1 = p1
self.p2 = p2
def val(self):
return (self.p1,self.p2)
def __lt__( self, other):
return self.val() < other.val()
def __le__( self, other):
return self.val() <= other.val()
def __eq__( self, other):
return self.val() == other.val()
def __ne__( self, other):
return self.val() != other.val()
def __gt__( self, other):
return self.val() > other.val()
def __ge__( self, other):
return self.val() >= other.val()
def __hash__(self):
return self.val().__hash__()
b1 = Bar('a','b')
b2 = Bar('c','d')
b3 = Bar('a','b')
print b1 == b3
d = {}
d[b1] = 'hoge'
d[b2] = 'fuge'
print "b1:hash = %d" % b1.__hash__()
print "b2:hash = %d" % b2.__hash__()
print "b3:hash = %d" % b3.__hash__()
print b3 in d.keys()
print d[b3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment