我有一个元组列表
[(1, "aa"), (1, "bb"), (2, "aa"), (3, "cc"), (4, "cc"), (1, "aa")]
我想将其转换为此
[(1, "aa"), (2, "aa+1"), (1, "aa+2"), (1, "bb"), (3, "cc"), (4, "cc+1")]
顺序无关紧要。
每个元素在snd
中是唯一的
我当时在想一些可行的方法
identifier :: [String]
identifier = map (\ x -> (\ a b -> b ++ show a) x "+") [1, 2 .. ]
unUniqueNumbered :: [(String, String)] -> [(String, String)]
unUniqueNumbered = zipWith (\b a -> (fst a, snd a ++ b)) identifier
uniquifySND :: [(String, String)] -> [(String, String)]
uniquifySND theList = concat $ groupBy ((==) `on` snd) theList
问题在于,groupBy
仅将相邻的重复元素分组。
我需要更改什么?
答案 0 :(得分:1)