我试图一个接一个地删除一组不同的元组列表。列表如下所示:
A = [
(('X','Y','Z',2,3,4), ('A','B','C',5,10,11)),
(('A','B','C',5,10,11), ('X','Y','Z',2,3,4)),
(('T','F','J',0,1,0), ('H','G','K',2,8,7)),
... ]
B = [
(('X','Y','Z',0,0,0), ('A','B','C',3,3,2)),
(('A','B','C',3,3,2), ('X','Y','Z',0,0,0)),
(('J','K','L',5,4,3), ('V','T','D',5,10,12)),
... ]
我正在运行(例如列表 A):
from collections import OrderedDict
values = [[x,y] for x, y in OrderedDict.fromkeys(frozenset(x) for x in A)]
我会得到:
A = [
(('X','Y','Z',2,3,4), ('A','B','C',5,10,11)),
(('T','F','J',0,1,0), ('H','G','K',2,8,7)),
... ]
但是,如果我对 B 重复,我可能会选择第二个元组而不是第一个:
B = [
(('A','B','C',3,3,2), ('X','Y','Z',0,0,0)),
(('J','K','L',5,4,3), ('V','T','D',5,10,12)),
... ]
理想情况下,B 应该是:
B = [
(('X','Y','Z',0,0,0), ('A','B','C',3,3,2)),
(('J','K','L',5,4,3), ('V','T','D',5,10,12)),
... ]
对于字符串序列,我需要它们相同,因为我将使用它们来连接 A、B 等中的浮点数。我很高兴知道是否有办法让去重列表的选择方法保持不变。谢谢!