Skip to content

Instantly share code, notes, and snippets.

@waddles
Created February 12, 2015 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waddles/1a9c09d904f74d946208 to your computer and use it in GitHub Desktop.
Save waddles/1a9c09d904f74d946208 to your computer and use it in GitHub Desktop.
Go Tour Exercise on Maps - http://tour.golang.org/moretypes/19
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
m := make(map[string]int)
words := strings.Fields(s)
for _,val := range words {
m[val] += 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