Created
October 26, 2016 09:04
-
-
Save hsleonis/089544b3a2364338bf81912bdccb23be to your computer and use it in GitHub Desktop.
Counts number of each word in a string
This file contains hidden or 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
import ( | |
_ "fmt" | |
"strings" | |
) | |
func WordCount(s string) map[string]int { | |
word:=make(map[string]int) | |
m:=strings.Fields(s) | |
for _,w:=range m{ | |
word[w]++ | |
} | |
return word | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment