如何拆分字符串列表以查找Haskell中的所有重复项?

时间:2015-09-27 23:01:03

标签: string haskell filter split

假设我的[String]为["one", "one", "two", "three", "three", "three"]

我如何将此[String]拆分为

的[[String]]

[["one", "one"], ["two"], ["three", "three", "three"]]

感谢您的时间

1 个答案:

答案 0 :(得分:3)

如果要按照示例输入中的相等性对连续值进行分组,则执行

Prelude> Data.List.group ["one", "one", "two", "three", "three", "three"]                               
[["one","one"],["two"],["three","three","three"]]

否则,您可能希望对列表进行排序以获得彼此相邻的相等值。