3 ms·
Yes, Python supports in place operators to avoid this: def __iadd__(self, other): if isinstance(other, dict): self.update(other)
by Znafon 8y ago
Yes, Python supports in place operators to avoid this:
def __iadd__(self, other):
if isinstance(other, dict):
self.update(other)
return self
This would get called for `d += other`.
- mroche 8y agoMy follow up question would be why not do this for both union functions? I don’t see why they would want to have two functions that do the exact same thing (called differently, though) be written in two different ways.