Word Frequency Counter
Count how many times each word appears using a map.
package main
import (
"fmt"
"strings"
)
func main() {
text := "the cat sat on the mat the cat"
words := strings.Split(text, " ")
counts := map[string]int{}
for _, word := range words {
counts[word]++
}
for word, count := range counts {
fmt.Printf("%s: %d\n", word, count)
}
}