john
john

Reputation: 2164

How to remove duplicates from a list in Clojure?

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

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

Upvotes: 18

Views: 11422

Answers (3)

John Asbaghi
John Asbaghi

Reputation: 182

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

Upvotes: 5

missingfaktor
missingfaktor

Reputation: 92056

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

Upvotes: 42

sepp2k
sepp2k

Reputation: 370162

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

Upvotes: 11

Related Questions