标签:
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?"))
}
标签:
原文地址:http://www.cnblogs.com/enfreeworld/p/gostudy_map.html