On Aug 3, 4:07 pm, kj <no.em...@please.post> wrote: > I use the term "no-clobber dict" to refer to a dictionary D with > the especial property that if K is in D, then > > D[K] = V > > will raise an exception unless V == D[K]. In other words, D[K] > can be set if K doesn't exist already among D's keys, or if the > assigned value is equal to the current value of D[K]. All other > assignments to D[K] trigger an exception. > > The idea here is to detect inconsistencies in the data. > > This is a data structure I often need. Before I re-invent the > wheel, I thought I'd ask: is it already available? > > TIA! > > kynn
Not sure if something like this already exists, but it would be trivial to implement by overriding dict.__setitem__() badda-bing baby! -- http://mail.python.org/mailman/listinfo/python-list