Christoph Zwerschke <[EMAIL PROTECTED]> writes: > Mike Meyer wrote: >> Any object for which hash() returns an appropriate value(1) can be >> used as a dictionary key/set element. Lists, sets and dicts are not >> hashable, and can not be used. Tuples can be used if all the things >> they contain are hashable. instances of all other builin types can be >> used. Instances of most classes written in Python can be used(2). >> 1) See the __hash__ documentation for details on what an approriate >> value is. >> 2) Instances that have a __hash__ method that returns an appropriate >> value can be used. Instances that don't have a __cmp__ or an __eq__ >> method can be used even if they don't have a __hash__ method. > > I think that is not so bad. How about this simplification: > > Any hashable object(1) can be used as a dictionary key/set > element. Lists, sets and dicts are not hashable, and can not be > used. Tuples can be used if all the things they contain are > hashable. Instances of all other built-in types and most user-defined > classes are hashable. > > (1) Objects for which the hash() function returns an appropriate > (proper?) value. See the __hash__ documentation for details.
I think that will do quite nicely, as the information about __hash__, __cmp__ and __eq__ are all in the __hash__ documentation. You wrote it - why don't you submit a PR with it? <nmike -- Mike Meyer <[EMAIL PROTECTED]> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list