Skip to content

Instantly share code, notes, and snippets.

@kimitoboku
Created May 3, 2014 08:01
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 kimitoboku/11493597 to your computer and use it in GitHub Desktop.
Save kimitoboku/11493597 to your computer and use it in GitHub Desktop.
A Tour of Go#41
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
words := strings.Split(s, " ")
m := make(map[string]int)
for _, str := range words {
_, exist := m[str]
if exist == false {
m[str] = 1
} else {
m[str] = m[str] + 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