Counting unique elements in a list

后端 未结 5 614
长情又很酷
长情又很酷 2020-12-03 21:48

Is there a straight-forward combination of standard higher-order functions to count the unique elements in a list?

For example the result for

[1, 1,          


        
5条回答
  •  眼角桃花
    2020-12-03 22:01

    What your talking about is just run length encoding on sorted data: the free online book Real World Haskell has a great example of this. You will want to sort the list before you put it through the runLengthEncoder.

提交回复
热议问题