Skip to content

Instantly share code, notes, and snippets.

@flc
Created August 28, 2013 18:50
Show Gist options
  • Save flc/6369774 to your computer and use it in GitHub Desktop.
Save flc/6369774 to your computer and use it in GitHub Desktop.
A Tour of Go - Exercise: Maps http://tour.golang.org/#41
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
words := strings.Fields(s)
ret := make(map[string]int)
for _, word := range(words) {
ret[word] += 1
}
return ret
}
func main() {
wc.Test(WordCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment