从Python字典中删除多个键 [英] Remove more than one key from Python dict
本文介绍了从Python字典中删除多个键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种有效的快捷方式可以一次从python字典中删除多个键?
Is there any efficient shortcut method to delete more than one key at a time from a python dictionary?
例如;
x = {'a': 5, 'b': 2, 'c': 3}
x.pop('a', 'b')
print x
{'c': 3}
推荐答案
使用 del
声明:
x = {'a': 5, 'b': 2, 'c': 3}
del x['a'], x['b']
print x
{'c': 3}
这篇关于从Python字典中删除多个键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文