I need a dictionary class that implements a method intersection_updatesimilar in spirit to dict.update, but restricting updates to, only those keys that are already present in the calling instance (see below for some implementation examples).
But, in the spirit of "Avoiding Wheel Rollback", before I leave the implementation (and write tests for, etc.) of the mapping class with this additional functionality, it does something similar in the more or less standard module
To be clear, the method intersection_updateI have in mind will do something like this:
def intersection_update(self, other):
for k in self.viewkeys() & other.viewkeys():
self[k] = other[k]
... although the actual implementation may try to perform some possible optimizations, for example, for example:
def intersection_update(self, other):
x, y = (self, other) if len(self) < len(other) else (other, self)
for k in x.iterkeys():
if k in y:
self[k] = other[k]
: ", Python, [ intersection_update]?", , , , , "" Python, , , , , (, , ) .