On Dec 11, 9:21 am, bOR_ <[EMAIL PROTECTED]> wrote:
> I thought I remembered there was a method in the api somewhere that
> would count the frequency of each unique item in a collection, but I
> can't find it anymore. What would be a brief way to write that in
> clojure?

I think what you want is:

    (defn frequencies [coll]
      (reduce
       (fn [counts x]
         (assoc counts x
                (if-let [c (counts x)] (inc c) 1)))
       {} coll))

user=> (frequencies [:a :a :b :a :b])
{:b 2, :a 3}

-Stuart Sierra
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to