Login
|
Signup
langref.org
-
perl
add..
all
clojure
cpp
csharp
erlang
fantom
fsharp
go
groovy
haskell
java
ocaml
php
python
ruby
scala
Home
All
Solved
Unsolved
Strings
Numbers
Regex
Lists
Maps
Structure
Files
Dates
OOP
Networking
XML
Algorithms
Misc
Parallel
View Problem
Maps
Algorithms
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
perl
foreach(@list) {
$histogram{$_}++;
}
@list=('a','b','a','c','b','b');
foreach(@list) {
$histogram{$_}++;
}
foreach(keys(%histogram)) {
print "$_=>$histogram{$_}\n";
}
perl
$histogram{$_}++ for @list;
$histogram{$_}++ for @list;
Submit a new solution for
perl
There are 37 other solutions in
additional
languages (
clojure
,
cpp
,
csharp
,
erlang
...)