class md5Check(object):
"""docstring for md5Check"""
def __init__(self, md5, fullpath):
super(md5Check, self).__init__()
self.fullpath = fullpath
self.md5 = md5
fullpath = ""
md5 = ""
imageFiles = list()
temp = md5Check(md5Sum, fullpath)
imageFiles.append(temp)
我想删除我的列表中的重复项,该列表由我的 md5Check 数据结构组成。类实例 md5 变量可以识别重复项。删除重复项的好方法是什么?
最佳答案
由于 md5
是可哈希的,因此您可以使用 set
来跟踪看到的 md5
值。
seen = set()
imageFiles = [x for x in imageFiles if x.md5 not in seen and not seen.add(x.md5)]
如果您不喜欢副作用:
seen = set()
imageFiles_new = []
for x in imageFiles:
if x.md5 not in seen:
imageFiles_new.append(x)
seen.add(x.md5)
imageFiles = imageFiles_new
关于python - 消除自定义数据结构的重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24639363/