// Iterate through the documents, appending the document number to the set for each top_id it contains
for n, document in enumerate(corpus):
doc_words = frozenset(x[0] for x in document)
top_ids_in_doc = top_ids.intersection(doc_words)
if len(top_ids_in_doc) > 0:
for id in top_ids_in_doc:
per_topic_postings[id].add(n)
num_docs = len(corpus)
After Change
// Iterate through the documents, appending the document number to the set for each top_id it contains
for n, document in enumerate(corpus):
doc_words = frozenset(x[0] for x in document)
for word_id in top_ids.intersection(doc_words):
per_topic_postings[word_id].add(n)
num_docs = len(corpus)
return per_topic_postings, num_docs