Skip to content

Instantly share code, notes, and snippets.

@davegardnerisme
Created January 28, 2013 17:49
Show Gist options
  • Select an option

  • Save davegardnerisme/4657568 to your computer and use it in GitHub Desktop.

Select an option

Save davegardnerisme/4657568 to your computer and use it in GitHub Desktop.
Learning go!
package main
import (
"tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
list := strings.Fields(s)
wc := map[string]int{}
for _, value := range list {
_, ok := wc[value]
if !ok {
wc[value] = 0
}
wc[value]++
}
return wc
}
func main() {
wc.Test(WordCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment