问题描述:

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')
相关阅读:
Top