View Problem

Create a histogram map from a list

Given the list [a,b,a,c,b,b], produce a map {a:2, b:3, c:1} which contains the count of each unique item in the list
ExpandDiskEdit
groovy
histogram = [:]
list.each { item ->
if (!histogram.containsKey(item)) histogram[item] = 0
histogram[item]++
}
ExpandDiskEdit
groovy
histogram = [:]
list.each { histogram[it] = (histogram[it] ?: 0) + 1 }

Submit a new solution for groovy
There are 37 other solutions in additional languages (clojure, cpp, csharp, erlang ...)