擅长:python、mysql、java
<p>另一种方式</p>
<pre><code>delete_word = input('enter an animal to delete from file') # use raw_input on python 2
with open('words.txt') as fin, open('words_cleaned.txt', 'wt') as fout:
list(fout.write(line) for line in fin if line.rstrip() != delete_word)
</code></pre>