cmp of multiple attributes (WAS: Why are tuples immutable?)
Roy Smith
roy at panix.com
Thu Dec 16 16:32:17 EST 2004
More information about the Python-list mailing list
Thu Dec 16 16:32:17 EST 2004
- Previous message (by thread): cmp of multiple attributes (WAS: Why are tuples immutable?)
- Next message (by thread): cmp of multiple attributes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
>Roy Smith wrote: >> def __cmp__ (self, other): >> # I wish there was a less verbose way to do this! >> if self.block < other.block: >> return -1 >> if self.block > other.block: >> return 1 >> if self.lot < other.lot: >> return -1 >> if self.lot > other.lot: >> return 1 >> return 0 Steven Bethard <steven.bethard at gmail.com> wrote: >Does this do what you want? >... def __cmp__(self, other): >... return (cmp(self.block, other.block) or >... cmp(self.lot, other.lot)) Yes, that's exactly what I was after. Like so many things, it's obvious once it's pointed out to you. Thanks!
- Previous message (by thread): cmp of multiple attributes (WAS: Why are tuples immutable?)
- Next message (by thread): cmp of multiple attributes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list