当前位置: 动力学知识库 > 问答 > 编程问答 >

python - How to remove an item from a "collections.defaultdict"?

问题描述:

I have a collections.defaultdict as follows:

mydict = defaultdict(lambda:0)

mydict['stock1'] = 1.11

mydict['stock2'] = 2.22

mydict['stock3'] = 3.33

Now I want to remove the second item completely, how can I do that?

Maybe there is little seens to remove that but just simply set it to zero as follow:

mydict['stock2'] = 0

网友答案:

See the documentation, it's just like the ordinary dictionary. You can use either:

  • del mydict['stock2']
  • mydict.pop('stock2')
分享给朋友:
您可能感兴趣的文章:
随机阅读: