frequencies

clojure.core

  • (frequencies coll)
Returns a map from distinct items in coll to the number of times
they appear.

1 Example top

  • user=> (frequencies ['a 'b 'a 'a])
    {a 3, b 1}
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:6255 top

(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)))
Vars in clojure.core/frequencies:
Used in 0 other vars

Comments top

2 comment(s) for frequencies.

(fn [coll]
   (let [gp (group-by identity coll)] 
      (zipmap (keys gp) (map #(count (second %)) gp))))
(into {} (for [[k v] (group-by identity "abbbc")] [k (count v)]))
Log in to add a comment.