Returns a map from distinct items in coll to the number of times
they appear.
(defn frequencies
"Returns a map from distinct items in coll to the number of times
they appear."
{:added "1.2"
:static true}
[coll]
(persistent!
(reduce (fn [counts x]
(assoc! counts x (inc (get counts x 0))))
(transient {}) coll)))
Comments top
1 comment(s) for frequencies.
(fn [coll] (let [gp (group-by identity coll)] (zipmap (keys gp) (map #(count (second %)) gp))))(fn [coll] (let [gp (group-by identity coll)] (zipmap (keys gp) (map #(count (second %)) gp))))