Maybe in certain case you could use hash to compare objects (hashable
of course) quicker by comparing there hash values, if the hash values
are the same you test the equality between the objects. <br>
<br>
But the sets and dicts cover the greatest part of the use of hash.<br>
(Personally, I never used that explicitly in my programs)<br>
<br>
Cyril<br>
<br>
<br><br><div><span class="gmail_quote">On 7/21/05, <b class="gmail_sendername">Michael Hudson</b> <<a href="mailto:mwh@python.net">mwh@python.net</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Steven D'Aprano <<a href="mailto:steve@REMOVETHIScyber.com.au">steve@REMOVETHIScyber.com.au</a>> writes:<br><br>> Do people often use hash() on built-in types?<br><br>Only implicitly.<br><br>> What do you find it useful for?
<br><br>Dictionaries :)<br><br>> How about on custom classes?<br><br>Same here.<br><br>> Can anyone give me some good tips or hints for writing and using<br>> hash functions in Python?<br><br>Well, the usual tip for writing them is, don't, unless you need to.
<br><br>If implement __eq__, then you need to, so it's fairly common to just<br>hash a tuple containing the things that are considered by the __eq__<br>method.  Something like:<br><br>class C(object):<br>    def __init__(self, a, b, c):
<br>        self.a = a<br>        self.b = b<br>        self.c = c<br>    def __eq__(self, other):<br>        return self.a == other.a and self.b == other.b<br>    def __hash__(self):<br>        return hash((self.a, self.b
))<br><br>Cheers,<br>mwh<br><br>--<br>  I'm a keen cyclist and I stop at red lights.  Those who don't need<br>  hitting with a great big slapping machine.<br>                                          
-- Colin Davidson, cam.misc<br>--<br><a href="http://mail.python.org/mailman/listinfo/python-list">http://mail.python.org/mailman/listinfo/python-list</a><br></blockquote></div><br>