[Python-bugs-list] [ python-Bugs-791397 ] Tutorial: mutable objects may be keys

SourceForge.net noreply at sourceforge.net
Fri Aug 22 21:35:32 EDT 2003


Bugs item #791397, was opened at 2003-08-19 13:04
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=791397&group_id=5470

Category: Documentation
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Brian Victor (brianhv)
Assigned to: Nobody/Anonymous (nobody)
Summary: Tutorial: mutable objects may be keys

Initial Comment:
http://python.org/doc/tut/node7.html#SECTION007400000000000000000

The tutorial section 5.4 ("Dictionaries") says, "Unlike
sequences, which are indexed by a range of numbers,
dictionaries are indexed by keys, which can be any
immutable type; strings and numbers can always be
keys."  This strongly implies that only immutable
objects may be keys, and I always assumed that to be
the case.  I have recently learned that is not true.

I would suggest a change along the lines of "which can
be any immutable type or mutuable types under some
circumstances," with a link to further elaboration on
what is required for a type to be hashable.

----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2003-08-22 22:35

Message:
Logged In: YES 
user_id=80475

I prefer the current wording which shifts you away perilous 
paths.  It is possible to create a hashable, mutable class, but 
you had better know what you're doing if you want to use the 
objects as dictionary keys and expect to be able to retrieve 
them later

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=791397&group_id=5470



More information about the Python-bugs-list mailing list