Это мой код, и я продолжаю получать объект NoneType, который не является повторяемой ошибкой во второй последней строке.
for key, value in termdic.items():
# value = List of lists where 1st entry is a documentID and the second is a position
i=0
temp = []
for v in value:
# print(v)
current_doc = v[0]
if i==0:
prev_doc = v[0]
i+=1
if (prev_doc == current_doc):
temp.append(v[1])
if (prev_doc != current_doc):
if key not in term_position_dic:
# initialize
term_position_dic[key] = [[prev_doc,len(temp),temp]]
# encode(temp)
# delta_position_dic[key] = [[prev_doc,len(temp),temp]]
else:
term_position_dic[key].append([prev_doc,len(temp),temp])
# encode(temp)
# delta_position_dic[key].append([prev_doc,len(temp),temp])
# We are in the reset phase
prev_doc= current_doc
temp = [v[1]]
Примечание: Termdic - это dic of key = term и value = список списков, которые= [[docID, количество вхождений, [список позиций слова в документе.] *
uncompressed_dic = {}
for k, value in term_position_dic.items():
temparray = []
for v in value:
docID = v[0]
count = v[1]
poslist = v[2]
tarray = [docID, count].extend(poslist)
temparray.extend(tarray)
uncompressed_dic[k] = temparray
Кроме того, почему docID, count, posList будет None после итерации, он показывает, как естькогда я его печатаю, но когда последний массив создается, все значения равны None.