Last active
February 20, 2021 08:52
-
-
Save medecau/7ea2751a962eef1db4634011b9eb9e74 to your computer and use it in GitHub Desktop.
Callable dictionary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class callable_dict(dict): | |
def __call__(self, **kwargs): | |
nd = self.copy() | |
nd.update(**kwargs) | |
return nd | |
d = callable_dict(a=1, b=2) | |
nd = d(b=3, c=4) | |
print(d) | |
print(nd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment