package main
import (
"strings"
"fmt"
)
// 返回各个单词数量统计的map
func WordCount(s string) map[string]int {
m := make(map[string] int)
for _, word := range strings.Fields(s) {
m[word] ++
}
return m
}
func main() {
fmt.Println(WordCount("I am learning Go!"))
fmt.Println(WordCount("How do you do?"))
}
时间: 2024-10-28 22:05:17