October 11, 2019
Python: 从dict字典中删除键的不同方法 del vs dict.pop(), Different ways to Remove a key from Dictionary in Python | del vs dict.pop()
在本文中,我们将讨论从python中的字典中删除键的不同方法。
假设我们有一个字符串和整数的字典,即
# Dictionary of strings and int
wordFreqDic = {
"Hello": 56,
"at" : 23 ,
"test" : 43,
"this" : 43
}
现在我们要从字典中删除键为“ at”的项目。让我们看看如何做到这一点,
使用del从字典中删除键
del d[key]
del语句从字典中删除给定的项目。如果字典中不存在给定的键,则它将抛出KeyError。
让我们用它从上述字典中删除密钥,
'''
Deleting an entry from dictionary using del
'''
# If… Read More