I am using defaultdict(set) to populate an internal mapping in a very large data structure. After it\'s populated, the whole structure (including the mapping) i
You could make a class that holds a reference to your dict and prevent setitem()
from collections import Mapping
class MyDict(Mapping):
def __init__(self, d):
self.d = d;
def __getitem__(self, k):
return self.d[k]
def __iter__(self):
return self.__iter__()
def __setitem__(self, k, v):
if k not in self.d.keys():
raise KeyError
else:
self.d[k] = v