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

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

Python crifan 6078浏览 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,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.189 seconds, using 21.99MB memory