Skip to content

Instantly share code, notes, and snippets.

@wlaurance
Created May 12, 2014 00:24
Show Gist options
  • Save wlaurance/f2a2318edbef9becb719 to your computer and use it in GitHub Desktop.
Save wlaurance/f2a2318edbef9becb719 to your computer and use it in GitHub Desktop.
word count
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
words := strings.Fields(s)
counts := make(map[string]int)
for _, word := range words {
counts[word] += 1
}
return counts
}
func main() {
wc.Test(WordCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment