boltons
boltons copied to clipboard
dict get_all()
def get_all(map, **defaults):
return {key: map.get(key, default) for key, default in defaults.items()}
found this to be handy e.g. when extracting data from query parameters, flags or similar
very concise way to normalize an input dict by extracting only the keys you are interested in, and defaulting and missing keys
I like it. Not sure about the name, but it is an elegant solution to a common problem.
I just noticed there is no pull request. Are you planning on submitting one?
would you like to get your name in the contributors? :-) please feel free