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

后端 未结 9 1088
广开言路
广开言路 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:15

    This AutoVivification class is not the magic you are looking for.

    Check out collections.defaultdict from the standard library. Your inner dicts should be defaultdicts that default to integer values, and your outer dicts would then be defaultdicts that default to inner-dict values.

提交回复
热议问题