Skip to content

Instantly share code, notes, and snippets.

@hsleonis
Created October 26, 2016 09:04
Show Gist options
  • Save hsleonis/089544b3a2364338bf81912bdccb23be to your computer and use it in GitHub Desktop.
Save hsleonis/089544b3a2364338bf81912bdccb23be to your computer and use it in GitHub Desktop.
Counts number of each word in a string
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