Skip to content

Instantly share code, notes, and snippets.

@Pygmalion69
Created February 28, 2020 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pygmalion69/1dcc28167ba4a4459de66dc7d4d4ff6b to your computer and use it in GitHub Desktop.
Save Pygmalion69/1dcc28167ba4a4459de66dc7d4d4ff6b to your computer and use it in GitHub Desktop.
A Tour of Go - Exercise: Maps
// https://tour.golang.org/moretypes/23
package main
import (
"strings"
"golang.org/x/tour/wc"
)
func WordCount(s string) map[string]int {
m := make(map[string]int)
for _, word := range strings.Fields(s) {
m[word]++
}
return m
}
func main() {
wc.Test(WordCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment