我有一个很大的文本文件,包含900000行。我需要计算没有'year1995'和'year1996'的行数。我的做法如下:
fname = r"data.txt"
with open(fname,'r') as fi:
lines = fi.read().splitlines()
print len(lines)
test = [l for l in lines if 'year1995' or 'year1996' not in l]
print len(test)
但是我的代码没有产生预期的结果。
有什么想法吗?