擅长:python、mysql、java
<p>根据对这个问题的评论,可以这样做:</p>
<pre><code>first = set(x.strip() for x in open("tmp1.txt").readlines())
second = set(x.strip() for x in open("tmp2.txt").readlines())
print second - first
</code></pre>
<p>但是,如果我们认真对待“大”,在处理之前加载整个文件可能会占用比机器上可用的内存更多的内存。如果第一个文件足够小,可以放入内存,而第二个文件不够小,则可以执行以下操作:</p>
<pre><code>first = set(x.strip() for x in open("tmp1.txt").readlines())
for line in open("tmp2.txt").xreadlines():
line = line.strip()
if line not in first:
print line
</code></pre>
<p>如果第一个文件太大,我想你需要求助于数据库。你知道吗</p>