📜  python dict 排除键 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:18.848000             🧑  作者: Mango

代码示例1
>>> my_dict = {
...     "keyA": 1,
...     "keyB": 2,
...     "keyC": 3
... }
>>> invalid = {"keyA", "keyB"}
>>> def without_keys(d, keys):
...     return {x: d[x] for x in d if x not in keys}
>>> without_keys(my_dict, invalid)
{'keyC': 3}