boltons icon indicating copy to clipboard operation
boltons copied to clipboard

dict get_all()

Open kurtbrose opened this issue 4 years ago • 3 comments

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

kurtbrose avatar Oct 14 '20 15:10 kurtbrose

I like it. Not sure about the name, but it is an elegant solution to a common problem.

mblahay avatar Nov 13 '20 16:11 mblahay

I just noticed there is no pull request. Are you planning on submitting one?

mblahay avatar Nov 13 '20 16:11 mblahay

would you like to get your name in the contributors? :-) please feel free

kurtbrose avatar Nov 13 '20 19:11 kurtbrose