我有以下设置:
co_occurrences = defaultdict(lambda: defaultdict(int))
# Populate the dictionary...
for word, occurrence_vector in co_occurrences:
if word == "__length": continue
for file_name, occurrence_count in occurrence_vector:
co_occurrences[word][file_name] = occurrence_count / co_occurrences["__length"][file_name]
这条线是:
co_occurrences[word][file_name] = occurrence_count / co_occurrences["__length"][file_name]
危险的?所谓危险,我的意思是我想对每个键进行一次且仅一次迭代,因此任何修改此行为的代码都是危险的。我觉得可能是因为我正在修改我正在迭代的数据结构。