我正在尝试解决go tour #43 中的难题,但我不明白为什么我的单词计数器不起作用。“print”似乎打印了预期值,但无论计数多少,测试都只看到“1”。
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
"unicode/utf8"
)
func WordCount(s string) map[string]int {
// explode the string into a slice without whitespaces
ws := strings.Fields(s)
//make a new map
c := make(map[string]int)
//iterate over each word
for _, v := range ws{
c[v] = utf8.RuneCountInString(v)
}
print( c["am"])
return c
}
func main() {
wc.Test(WordCount)
}
www说
拉风的咖菲猫
相关分类