【发布时间】:2021-01-21 15:00:58
【问题描述】:
我需要在 python 中扫描 2 个文件并说出 file1 中的哪些单词也在 file2 中。我列出了 file2 中的所有单词,然后扫描 file1 中的行是否在列表中。
所以这很好用,但是大文件(如 500k)可能需要 1 小时以上,我想知道是否有更快的方法
提前致谢
(defined var etc and files)
a = []
for line in var:
a += [line]
teller = 0
for line1 in new_file:
if line1 not in a:
print(line1, file=filter, end='')
else:
teller += 1
print(line1, file=bad, end='' )
print('There were', teller, 'lines that were in the old file.')
【问题讨论】:
标签: python file for-loop search