Skip to content

Instantly share code, notes, and snippets.

@stamler
Created August 6, 2013 18:59
Show Gist options
  • Save stamler/6167530 to your computer and use it in GitHub Desktop.
Save stamler/6167530 to your computer and use it in GitHub Desktop.
Exercise 40 (Maps) from tour.golang.org
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
// #40: Maps Exercise
func WordCount(s string) map[string]int {
output := make(map[string]int)
fields := strings.Fields(s)
for _, sub := range fields {
output[sub]++
}
return output
}
func main() {
wc.Test(WordCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment