Friday, July 08, 2011

Python: remove some entries from a dict

Remove a bunch of entries from a dict in an elegant way

Solution 1:

map(lambda name: dict.pop(name, None), ['some_key', 'some_other_key', 'bleee'])

Solution 2:
My coworker Dave came up with an even better way to do this thing:

map(dict.pop, ['some_key', 'some_other_key', 'bleee'], [])

No comments:

Post a Comment