任何人都可以告诉我为什么第二个循环应该计算行数?我是Python和编程的新手,所以它很混乱。
import re
number_lines=0
file=open('c:/users/jakub piotr/desktop/mbox-short.txt',"r")
number=(sum([int(x) for line in file for x in re.findall('^New.+: ([0-9]+)',line)]))
for line in file:
if line.startswith("New Revision:"):
number_lines+=1
print(number/number_lines)