Python: How to update value of key value pair in nested dictionary?

后端 未结 9 983
广开言路
广开言路 2021-01-21 20:25

i am trying to make an inversed document index, therefore i need to know from all unique words in a collection in which doc they occur and how often.

i have used this an

9条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-21 21:09

    It would be better to kick AutoVivification out all together, because it adds nothing.

    The following line:

    if (word == keyword and dictionary[keyword][filename] is not None):
    

    Doesn't work as expected, because of the way your class works, dictionary[keyword] will always return an instance of AutoVivification, and so will dictionary[keyword][filename].

提交回复
热议问题