Skip to content

Instantly share code, notes, and snippets.

@345161974
Forked from tetsuok/answer_word_count.go
Created May 1, 2017 06:48
Show Gist options
  • Save 345161974/d3cc14856012dab870a80c67bdc8629f to your computer and use it in GitHub Desktop.
Save 345161974/d3cc14856012dab870a80c67bdc8629f to your computer and use it in GitHub Desktop.
An answer of the exercise: Maps on a tour of Go
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
m := make(map[string]int)
a := strings.Fields(s)
for _, v := range a {
m[v]++
}
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