擅长:python、mysql、java
<p>我输入了@Alex建议的python代码。你知道吗</p>
<p>参见文档中的<a href="https://docs.python.org/2/library/sets.html" rel="nofollow noreferrer">^{<cd1>}</a>。你知道吗</p>
<p>我用<code>a.txt</code>和<code>b.txt</code>替换您的文本文件名以便于阅读。你知道吗</p>
<pre><code># First read the files and compare then using `set`
with open('a.txt', 'r') as newL, open('b.txt', 'r') as cleanL:
a = set(newL)
b = set(cleanL)
add_to_cleanL = list(a - b) # list with line in newL that are not in cleanL
add_to_newL = list(b - a) # list with line in cleanL that are not in newL
# Then open in append mode to add at the end of the file
with open('a.txt', 'a') as newL, open('b.txt', 'a') as cleanL:
newL.write(''.join(add_to_newL)) # append the list at the end of newL
cleanL.write(''.join(add_to_cleanL)) # append the list at the end of cleanL
</code></pre>