最新消息:20210917 已从crifan.com换到crifan.org

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

Python crifan 5724浏览 0评论

【背景】

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的健值对

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
92 queries in 0.200 seconds, using 23.27MB memory