python dict exclude keys

Solutions on MaxInterview for python dict exclude keys by the best coders in the world

showing results for - "python dict exclude keys"
Jaelynn
11 May 2020
1>>> my_dict = {
2...     "keyA": 1,
3...     "keyB": 2,
4...     "keyC": 3
5... }
6>>> invalid = {"keyA", "keyB"}
7>>> def without_keys(d, keys):
8...     return {x: d[x] for x in d if x not in keys}
9>>> without_keys(my_dict, invalid)
10{'keyC': 3}