我打開兩個文件 - 一個包含用於比較的新文件,另一個包含需要從此文件中刪除的時髦詞語。我這是迄今爲止功能:比較兩個文件中的行,如果它們相等,則刪除
def remove(file, buzz):
#outer for loop cycles through the buzz file
for line in buzz:
#inner for loop cycles through the new file
for line2 in file:
if (line==line2):
file.remove(line2)
else:
continue
其中file是已在main()
被打開,被傳遞到這一點,並buzz
是被打開,並從main()
傳遞的嗡嗡聲文件中的新文件。
刪除部分不起作用,新文件不變。
有什麼建議嗎?
一方面,文件對象沒有'remove'方法。 – elethan
兩個文件每行一個單詞嗎? –