How to remove duplicates from a list in Clojure?

别说谁变了你拦得住时间么 提交于 2020-12-25 01:45:35

问题


How can I remove duplicate values from a list? For example,

(remove-duplicates ["a" "b" "c" "a"])
  => ("a" "b" "c")

回答1:


user=> (distinct '(34 56 45 34 56 89 11 4 11 78 11))
(34 56 45 89 11 4 78)



回答2:


If you don't care about the order, you can simply convert the list to a set:

user=> (set '("a" "b" "c" "a" "lala" "d"))
#{"a" "b" "c" "d" "lala"}



回答3:


Dedupe is the faster equivalent for sorted lists since dedupe only keeps the prior element in memory.



来源:https://stackoverflow.com/questions/3742713/how-to-remove-duplicates-from-a-list-in-clojure

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!