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?"))
}
有疑问加站长微信联系(非本文作者)