久久久久久久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 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 天天爽天天操 | 欧美h视频 | 激情五月婷婷 | 亚洲国产精品人人爽夜夜爽 | 日韩在线播放视频 | 国产专区免费 | 99免费视频 | 日韩欧美国产精品一区二区 | 男女啪啪高潮无遮挡免费动态 | 欧美日韩视频网站 | 日本特黄特色aaa大片免费 | 欧美精品1区2区 | 狠狠操狠狠干 | 亚洲劲爆av | 国产激情一区二区三区 | 亚洲精彩视频在线观看 | www.一区二区三区.com | 亚洲欧美日韩中文字幕一区二区三区 | 亚洲成人在线网 | 欧美精品欧美精品系列 | 中文字幕第二区 | 日日操av | 人人干人人干人人 | 国产1区2区 | 91.xxx.高清在线 | 亚洲成人精品影院 | 视频一区二区在线观看 | 中文字幕国产日韩 | 91麻豆精品一区二区三区 | 欧美精品一区二区三区在线播放 | 国产精品区二区三区日本 | 免费特级黄毛片 | 一级片在线观看 | 国产中文字幕在线观看 | 伊人看片| 日韩欧美一区二区在线播放 | 亚洲免费在线视频 | 五月天婷婷狠狠 | 日日夜夜草 | 久久久青草婷婷精品综合日韩 | 日韩欧美综合 |