Trouble with max() and __cmp__()

Thomas Nelson thn at mail.utexas.edu
Sun Jan 28 15:46:07 EST 2007


My code:

class Policy(list):
    def __cmp__(self,other):
        return cmp(self.fitness,other.fitness)

j = Policy()
j.fitness = 3
k = Policy()
k.fitness = 1
l = Policy()
l.fitness = 5
print max([j,k,l]).fitness

prints 3, when I was expecting it to print 5.  What have I done wrong?

Thanks for the help,
THN




More information about the Python-list mailing list