开发者

How to remove duplicates from a list in Clojure?

开发者 https://www.devze.com 2023-01-16 13:02 出处:网络
How ca开发者_Python百科n I remove duplicate values from a list? For example, (remove-duplicates [\"a\" \"b\" \"c\" \"a\"])

How ca开发者_Python百科n I remove duplicate values from a list? For example,

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


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


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"}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消