如何对比两个列表,忽略每行一半的信息?
我需要输出File1中尚未存在的文件1中每个包的列表从SET(File1)中减去SET(file2)。 问题在于,这两个文件的每一行都是filepath以及包装的名称。 ie
file1完美介绍/package.rpm =/home/pasmoti/passoti/storage/package/potpack.rpm
file2 placteridendicenticalInformation/pockage.rpm =/repostorage/repo/repo/package/pockage.rpm
我无法从file1中删除文件路径1,将需要。我无法删除文件路径并将其放回其中,每个文件中都有一些不同的文件path。
到目前为止,代码:
file1 = []
file2 = []
with open('file1.txt') as f1
file1 = f1.read().splitlines()
with open(file2.txt') as f2
file2 = f2.read().splitlines()
diff = set(file1) - set(file2)
outfile = open ('Diff.txt','w')
for line in sorted (diff):
outfile.write(line)
outfile.write('/n')
这将在“ diff = set -set”行中首先放置一个集合的精确副本,因为它因名称中的filepath而无法从另一行中识别任何单行。
I need to output a list of every package that exists in file1 that does not already exist in file2, but I can't figure out how to get the code to ignore the '=' and every character after it each line when it tries to subtract set(file2) from set(file1).
The problem is that each line of these two files is a filepath along with the name of the package. I.E.
file1 PerfectlyIdenticalInformation/package.rpm=/home/pasmoti/storage/package/package.rpm
file2 PerfectlyIdenticalInformation/package.rpm=/repostorage/repo/package/package.rpm
I can't remove the file path from file1 either, I will need that. I can't remove the file paths and put them back on either, there are a few different filepaths in each file.
The code so far:
file1 = []
file2 = []
with open('file1.txt') as f1
file1 = f1.read().splitlines()
with open(file2.txt') as f2
file2 = f2.read().splitlines()
diff = set(file1) - set(file2)
outfile = open ('Diff.txt','w')
for line in sorted (diff):
outfile.write(line)
outfile.write('/n')
This outputs a precise copy of whichever set is put first in the "diff = set - set" line, because it does not recognize any single line from the other as being identical due to the filepath in the name.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论