Count Words in Go
import ( "strings" )
func WordCount(s string) map[string]int {
words := strings.Fields(s)
m := make(map[string]int)
for _, word := range words {
m[word] += 1
}
return m
}
Written by lukas
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Golang
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#