A newbie dictionary question

Greg Ewing greg.ewing at compaq.com
Mon Nov 8 12:14:12 CET 1999


Jan Vroonhof wrote:
> 
>     def __cmp__(self,other):
>         return self.nospaces() == other.nospaces()

A __cmp__ function is supposed to return -1, 0 or 1 corresponsing
to less than, equal to or greater than. Try it this way:

     def __cmp__(self,other):
         return cmp(self.nospaces(), other.nospaces())

Greg




More information about the Python-list mailing list