gpt4 book ai didi

python - 从 Python 字典中删除多个键

转载 作者:太空狗 更新时间:2023-10-30 00:26:58 29 4
gpt4 key购买 nike

是否有任何有效的快捷方式可以从 python 字典中一次删除多个键?

例如;

x = {'a': 5, 'b': 2, 'c': 3}
x.pop('a', 'b')
print x
{'c': 3}

最佳答案

使用the del statement :

x = {'a': 5, 'b': 2, 'c': 3}
del x['a'], x['b']
print x
{'c': 3}

关于python - 从 Python 字典中删除多个键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8448202/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com