heapq以相同的方式
list.sort对对象进行排序,因此只需
__cmp__()在类定义中定义一个方法,该方法会将自身与同一类的另一个实例进行比较:
def __cmp__(self, other): return cmp(self.intAttribute, other.intAttribute)
在Python 2.x中工作。
在3.x中使用:
def __lt__(self, other): return self.intAttribute < other.intAttribute

heapq以相同的方式
list.sort对对象进行排序,因此只需
__cmp__()在类定义中定义一个方法,该方法会将自身与同一类的另一个实例进行比较:
def __cmp__(self, other): return cmp(self.intAttribute, other.intAttribute)
在Python 2.x中工作。
在3.x中使用:
def __lt__(self, other): return self.intAttribute < other.intAttribute