Skip to content

Instantly share code, notes, and snippets.

@chaitanyakuber
Last active December 19, 2015 04:29
Show Gist options
  • Save chaitanyakuber/5897799 to your computer and use it in GitHub Desktop.
Save chaitanyakuber/5897799 to your computer and use it in GitHub Desktop.
maps exercise from "A Tour of Go"
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
ret := make(map[string]int)
for _, word := range strings.Fields(s) {
if _, ok := ret[word]; ok {
ret[word] += 1;
} else {
ret[word] = 1
}
}
return ret
}
func main() {
wc.Test(WordCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment