Skip to content

Instantly share code, notes, and snippets.

@siisee11
Created December 9, 2019 03:14
Show Gist options
  • Save siisee11/8837c0830b36c9dccbf1b3a8ab9a49c4 to your computer and use it in GitHub Desktop.
Save siisee11/8837c0830b36c9dccbf1b3a8ab9a49c4 to your computer and use it in GitHub Desktop.
word count with go
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
var m map[string]int
func WordCount(s string) map[string]int {
sub_string := strings.Fields(s)
m = make(map[string]int)
for i := 0 ; i < len(sub_string); i++ {
m[sub_string[i]]++
}
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