def __setitem__(self, key, value):
        """Checks if the key is allowed before setting the value"""
        if key in self._allowed_keys:
            super(RestrictedDict, self).__setitem__(key, value)
        else:
            raise KeyError("%s is not allowed as key" % key)
Checks if the key is allowed before setting the value
recipes/Python/578042_Restricted_dictionary/recipe-578042.py