Skip to content

Instantly share code, notes, and snippets.

@danimal141
Last active October 10, 2016 08:49
Show Gist options
  • Save danimal141/6681f5b03a4e6afb5faaf9491088d3c8 to your computer and use it in GitHub Desktop.
Save danimal141/6681f5b03a4e6afb5faaf9491088d3c8 to your computer and use it in GitHub Desktop.
A Tour of Go Exercise: Maps
package main
import (
"golang.org/x/tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
m := map[string]int{}
for _, v := range strings.Fields(s) {
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