1
我需要一個總和函數的幫助。我試圖在文檔中找到前綴爲「X-DSPAM-Confidence:」的所有行。在我提取它們之後,我想對它們調用sum()並計算平均值。謝謝,堆!在從文檔中提取的數字列表中調用sum()
for line in (fhand): line = line.rstrip() if not line.startswith("X-DSPAM-Confidence:"): continue else: n = float(line[line.find(":") + 1:]) a = sum(n) count = count + 1 print (n) print (a) print (total/count)
燁, 這樣可行!謝謝! –