What is the correct way to define __hash__?

greg greg at cosc.canterbury.ac.nz
Wed Oct 14 02:09:23 CEST 2009


Chris Rebert wrote:
> On Mon, Oct 12, 2009 at 7:04 PM, Steven D'Aprano
> <steven at remove.this.cybersource.com.au> wrote:
> 
>>This can be simplified to:
>>
>>return cmp((self._a, self._b), (other._a, other._b))
> 
> Assuming you're not using Python 3.x that is.

If you're using Python 3, you won't be writing a __cmp__
method in the first place.

-- 
Greg



More information about the Python-list mailing list