Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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