Skip to content

Instantly share code, notes, and snippets.

@sharathprabhal
Created November 13, 2013 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharathprabhal/7456280 to your computer and use it in GitHub Desktop.
Save sharathprabhal/7456280 to your computer and use it in GitHub Desktop.
import scala.collection.mutable.Map;
def getCounts[T](list: Seq[T]): Map[T, Int] = {
val map = Map.empty[T, Int];
list.foreach(x => {
if (!map.contains(x)) {
map.put(x, 0);
}
map.put(x, map(x) + 1);
});
return map;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment