Define a python dictionary with immutable keys but mutable values
Well, the question is in the title: how do I define a python dictionary with immutable keys but mutable values? I came up with this (in python 2.x): class FixedDict(dict): """ A dictionary with a fixed set of keys """ def __init__(self, dictionary): dict.__init__(self) for key in dictionary.keys(): dict.__setitem__(self, key, dictionary[key]) def __setitem__(self, key, item): if key not in self: raise KeyError("The key '" +key+"' is not defined") dict.__setitem__(self, key, item) but it looks to me (unsurprisingly) rather sloppy. In particular, is this safe or is there the risk of actually