Adding inverted index [Python]