我是 python 初学者,我有一个问题。我尝试从列表中获取前 10.000 个项目,但它返回了错误的数据。我注意到,因为我首先尝试获取前 10/20/50 个项目(我将结果打印在 .txt 中),但我什么也没得到。这是一些代码。
/*for key in docs:
T_buffer=docs[key]['tf'].items()
keyset.append(T_buffer)
*/
keyseta = list(itertools.chain(*keyset))
keyseta.sort(key=lambda z: z[1], reverse=True)
keyset=keyseta[:8000]
/*
#t0=time.time() #timer ON
#for infile in docs: #upologismos idf kai tf_idf
# for word in docs[infile]['tf']:
# docs[infile]['idf'][word]= idf(word,voc)
# docs[infile]['tf_idf'][word]= docs[infile]['idf'][word] * docs[infile]['tf'][word]
#print time.time()-t0, "seconds"
*/
loglista1 = open("log1.txt",'w')
print >>loglista1, keyset
列表包含以下数据:
[('uwm', 0.034482758620689655),
('s', 0.034482758620689655),
('the', 0.034482758620689655),
('have', 0.034482758620689655)...]