Skip to content

Instantly share code, notes, and snippets.

@janbenetka
Created October 13, 2021 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janbenetka/2c164710a3e59c11f73b08feb9f7b9d4 to your computer and use it in GitHub Desktop.
Save janbenetka/2c164710a3e59c11f73b08feb9f7b9d4 to your computer and use it in GitHub Desktop.
[Filter dictionary by keys] #python #dictionary #lambda
dict_filter = lambda x, y: dict([ (i,x[i]) for i in x if i in set(y) ])
large_dict = {"a":1,"b":2,"c":3,"d":4}
keys_to_remove = ("c","d")
updated_dict = dict_filter(large_dict, keys_to_remove)
print(updated_dict)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment