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
Not sure why you need nested dicts here. In a typical index scenario you have a forward index mapping
document id -> [word_ids]
and an inverse index mapping
word_id -> [document_ids]
Not sure if this is related here but using two indexes you can perform all kind of queries very efficiently and the implementation is straight forward since you don't need to deal with nested data structures.