我有一个元组列表。 每个元组也是一个元组。 对于每个外层元组,我有一个共轭元组。 我的意思是,如果我在列表中有(a,b),那么我也有(b,a)。 我想要的是从列表中删除共轭元组。
为了给你一个我的清单的具体例子,它是:
[((1,2,1,0),(5,2,1,0)),((2,4,4,0),(2,5,4,0)),((2,5,4,0),(2,4,4,0)),((3,1,1,0),(3,3,2,0)),((3,3,2,0),(3,1,1,0)),((5,1,7,0),(8,1,7,0)),((5,2,1,0),(1,2,1,0)),((5,5,8,0),(8,5,8,0)),((5,6,6,0),(8,6,8,0)),((5,9,9,0),(8,9,9,0)),((6,3,5,0),(6,8,9,0)),((6,8,9,0),(6,3,5,0)),((7,7,6,0),(9,7,6,0)),((8,1,7,0),(5,1,7,0)),((8,5,8,0),(5,5,8,0)),((8,6,8,0),(5,6,6,0)),((8,9,9,0),(5,9,9,0)),((9,7,6,0),(7,7,6,0))]
去除共轭元组后的结果应该是:
[((1,2,1,0),(5,2,1,0)),((2,4,4,0),(2,5,4,0)),((3,1,1,0),(3,3,2,0)),((5,1,7,0),(8,1,7,0)),((5,5,8,0),(8,5,8,0)),((5,6,6,0),(8,6,8,0)),((5,9,9,0),(8,9,9,0)),((6,3,5,0),(6,8,9,0)),((7,7,6,0),(9,7,6,0)),]
我尝试了几个小时没有成功。 任何帮助将不胜感激。
I have a list of tuples. Each tuple is a tuple as well. For each outer tuple, I have a conjugate tuple. By this I mean that if I have (a,b) in the list then I also have (b,a) as well. What I want is to remove the conjugate tuples from the list.
To give you a concrete example of my list here it is:
[((1,2,1,0),(5,2,1,0)),((2,4,4,0),(2,5,4,0)),((2,5,4,0),(2,4,4,0)),((3,1,1,0),(3,3,2,0)),((3,3,2,0),(3,1,1,0)),((5,1,7,0),(8,1,7,0)),((5,2,1,0),(1,2,1,0)),((5,5,8,0),(8,5,8,0)),((5,6,6,0),(8,6,8,0)),((5,9,9,0),(8,9,9,0)),((6,3,5,0),(6,8,9,0)),((6,8,9,0),(6,3,5,0)),((7,7,6,0),(9,7,6,0)),((8,1,7,0),(5,1,7,0)),((8,5,8,0),(5,5,8,0)),((8,6,8,0),(5,6,6,0)),((8,9,9,0),(5,9,9,0)),((9,7,6,0),(7,7,6,0))]
The result after removing the conjugate tuples should be:
[((1,2,1,0),(5,2,1,0)),((2,4,4,0),(2,5,4,0)),((3,1,1,0),(3,3,2,0)),((5,1,7,0),(8,1,7,0)),((5,5,8,0),(8,5,8,0)),((5,6,6,0),(8,6,8,0)),((5,9,9,0),(8,9,9,0)),((6,3,5,0),(6,8,9,0)),((7,7,6,0),(9,7,6,0)),]
I have tried for hours with no success. Any help will be appreciated.
最满意答案
“元组的每个元素也是一个元组”
removeConj xs = foldl f [] xs where f b a = if (elem (snd a, fst a) b) then b else (a:b)"Each element of the tuple is a tuple as well"
removeConj xs = foldl f [] xs where f b a = if (elem (snd a, fst a) b) then b else (a:b)更多推荐
发布评论