我有一组来自两个不同目录的文件名。在
currList=set(['pathA/file1', 'pathA/file2', 'pathB/file3', etc.])
我的代码正在处理这些文件,需要更改currList 通过将它与前一次迭代的内容进行比较,比如processLst。 为此,我计算了一个对称差:
^{pr2}$实际上,我需要对称的差异来操作basename(file1…)而不是 在完整的文件名(pathA/file1)上。在
我想我需要重新实现__eq__
操作符,但我不知道如何在python中实现它。在
__eq__
是正确的方法吗?
或者
这里有一个令牌(可能构造不好)
itertools
版本,如果速度成为一个问题,它应该运行得更快一点(尽管同意@Zarkonnen的一行代码非常好,所以+1在这里:)。在您可以使用生成器表达式的魔力来实现这一点。在
应该会成功的。它提供了出现在一个列表或另一个列表中的所有元素X,并且它们在两个列表中的基名不相同。在
编辑: 运行时使用:
^{pr2}$退货:
这似乎是正确的。在
相关问题 更多 >
编程相关推荐