Skip to content

Instantly share code, notes, and snippets.

@kaipakartik
Created December 25, 2013 01:01
Show Gist options
  • Save kaipakartik/8119269 to your computer and use it in GitHub Desktop.
Save kaipakartik/8119269 to your computer and use it in GitHub Desktop.
Solution to the maps exercise on golang http://tour.golang.org/#41
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
words := strings.Fields(s)
wordcount := make(map[string]int)
for _, word := range words {
wordcount[word] = wordcount[word] + 1
}
return wordcount
}
func main() {
wc.Test(WordCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment