Skip to content

Instantly share code, notes, and snippets.

@ericls
Created September 24, 2015 18:12
Show Gist options
  • Save ericls/289576be19e981ad0b62 to your computer and use it in GitHub Desktop.
Save ericls/289576be19e981ad0b62 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 := make(map[string]int)
for _,k := range strings.Fields(s) {
m[k] += 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