Skip to content

Instantly share code, notes, and snippets.

@ryochack
Created January 9, 2012 04:08
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 ryochack/1581012 to your computer and use it in GitHub Desktop.
Save ryochack/1581012 to your computer and use it in GitHub Desktop.
/*
* http://tour.golang.org/#45
* OR
* http://http://go-tour-jp.appspot.com/#44
*/
package main
import (
"tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
var strlist []string = strings.Fields(s)
var wordmap map[string]int
wordmap = make(map[string]int)
for _, str := range strlist {
wordmap[str]++
}
return wordmap
}
func main() {
wc.Test(WordCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment