美文网首页
Exercise : Map

Exercise : Map

作者: pathetic_old | 来源:发表于2017-03-02 12:09 被阅读0次
package main

import (
    "golang.org/x/tour/wc"
    "strings"   
)

func WordCount(s string) map[string]int {
    m := make(map[string]int)
    for _, each := range strings.Fields(s) {
        m[each] += 1
    }
    return m
}

func main() {
    wc.Test(WordCount)
}

相关文章

网友评论

      本文标题:Exercise : Map

      本文链接:https://www.haomeiwen.com/subject/iqvhgttx.html