久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

比較兩個文本文件并刪除python中的重復項

comparing two text files and remove duplicates in python(比較兩個文本文件并刪除python中的重復項)
本文介紹了比較兩個文本文件并刪除python中的重復項的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有兩個文本文件,file1file2.

I have two text files, file1 and file2.

File1 包含一堆隨機單詞,而 file2 包含我想在出現時從 file1 中刪除的單詞.有沒有辦法做到這一點?

File1 contains a bunch of random words, and file2 contains words that I want to remove from file1 when they occur. Is there a way of doing this?

我知道我可能應該在腳本中加入我自己的嘗試,至少是為了顯示努力,但老實說,這很可笑,不會有任何幫助.

I know I probably should include my own attempt at a script, to at least show effort, but to be honest it's laughable and wouldn't be of any help.

如果有人至少可以提供關于從哪里開始的提示,將不勝感激.

If someone could at least give a tip about where to start, it would be greatly appreciated.

推薦答案

獲取每個單詞:

f1 = open("/path/to/file1", "r") 
f2 = open("/path/to/file2", "r") 

file1_raw = f1.read()
file2_raw = f2.read()

file1_words = file1_raw.split()
file2_words = file2_raw.split()

如果您想要 file1 中不在 file2 中的唯一單詞:

if you want unique words from file1 that aren't in file2:

result = set(file1_words).difference(set(file2_words))

如果您關心從 file1 的文本中刪除單詞

if you care about removing the words from the text of file1

for w in file2_words:
    file1_raw = file1_raw.replace(w, "")

這篇關于比較兩個文本文件并刪除python中的重復項的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 精品国产乱码久久久久久闺蜜 | 琪琪午夜伦伦电影福利片 | 国产精品一区二区视频 | 久久天天躁狠狠躁夜夜躁2014 | 欧美一级大片免费看 | 一级日韩 | 粉嫩一区二区三区四区公司1 | 日韩精品免费看 | 日本在线播放一区二区 | 少妇一区在线观看 | 理伦毛片| 久久久久久综合 | 精品日韩在线 | 日韩a视频 | 欧美极品在线播放 | 欧美三区视频 | 神马久久春色视频 | 久久精品二区亚洲w码 | 免费在线观看av网站 | 精品国产一区二区三区性色av | 久久久久国产精品一区三寸 | 精品久久久久久久 | 国产精品亚洲综合 | 搞av.com| 最新日韩av | 亚洲欧美自拍偷拍视频 | 91精品国产色综合久久不卡98口 | 久久国产亚洲 | 午夜精品一区二区三区在线视 | h片在线观看网站 | 亚洲综合视频 | 亚洲综合色网站 | 欧美久操网 | av天天干| 亚洲国产网站 | 国产在线观看一区二区三区 | 成年人在线观看 | 日韩一区二区三区在线看 | 91精品国产91 | 一区二区三区av | 国产一区二区三区四区 |