How to define a class that can act as dictionary key?

Paul Rubin http
Tue Sep 15 14:31:33 CEST 2009


Christian Heimes <lists at cheimes.de> writes:
> >     def __hash__(self): return (self.term, self.doc_freq)
> > 
> > is probably the easiest.
> 
> The __hash__ function must return an integer:

Oh oops.  Try:

   def __hash__(self): return hash((self.term, self.doc_freq))



More information about the Python-list mailing list