Newbie Questions: Swithing from Perl to Python

Alex Martelli aleaxit at yahoo.com
Sun Oct 26 10:45:18 EST 2003


Luther Barnum wrote:
   ...
> really. It's just that I read that you cannot change a dictionary value

I suspect that may be a misreading of something else: "you cannot
use a mutable value as a dictionary key" (actually, you cannot use
a *non-hashable* value -- mutable values can still be hashable, but
normally they shouldn't be, unless the mutable part is just some kind
of implementation detail, such as a cache, not relevant from the
point of view of checking if an object "equals" another... but, this is
somewhat of a quibble:-).

Basically, this means you can't use (e.g.) a list, a dict, or a file object
as the key in a dictionary.  You CAN use a tuple (with hashable items), a 
string, a number, and so on, since in Python those are immutable.


Alex





More information about the Python-list mailing list