最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】Python中如何从字典中移除一个key和value的健值对

Python crifan 6521浏览

【背景】

Python中,已知对应的key,需要从python中的一个dict中,移除一个健值对

搜:

python dict remove key value

参考:

Best way to remove an item from a Python dictionary? – Stack Overflow

-》

pop

del?

python – Delete an element from a dictionary – Stack Overflow

-》

del

【总结】

直接用del即可,将某个key和value,从dict字典变量中移除:

        # remove offline user from current dict
        del gOnlineUserLocationDict[eachOfflineUser.id]

转载请注明:在路上 » 【已解决】Python中如何从字典中移除一个key和value的健值对

81 queries in 0.177 seconds, using 19.07MB memory