Skip to content

Instantly share code, notes, and snippets.

@praveenkumar
Created April 3, 2014 04:26
Show Gist options
  • Save praveenkumar/9948258 to your computer and use it in GitHub Desktop.
Save praveenkumar/9948258 to your computer and use it in GitHub Desktop.
Excersice: Maps
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
words := strings.Fields(s)
m := make(map[string]int)
for _, v := range(words) {
if m[v] != 0 {
m[v] = m[v]+1
}else {
m[v] = 1
}
}
return m
}
func main() {
wc.Test(WordCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment