Skip to content

Instantly share code, notes, and snippets.

@tai2
Last active April 22, 2019 02:54
Show Gist options
  • Select an option

  • Save tai2/08d90d77e164b9ba54cdfc3ccc74f065 to your computer and use it in GitHub Desktop.

Select an option

Save tai2/08d90d77e164b9ba54cdfc3ccc74f065 to your computer and use it in GitHub Desktop.
import "strings"
func WordCount(s string) map[string]int {
counts := make(map[string]int)
words := strings.Fields(s)
for _, word := range words {
count, ok := counts[word]
if ok {
counts[word] = count + 1
} else {
counts[word] = 1
}
}
return counts
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment