Created
December 9, 2019 03:14
-
-
Save siisee11/8837c0830b36c9dccbf1b3a8ab9a49c4 to your computer and use it in GitHub Desktop.
word count with go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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