MDGSF Software Engineer

[GO] word count

2017-09-19
GO

func WordCount(s string) map[string]int {

    m := make(map[string]int)

    words := strings.Fields(s)
    for _, v := range words {
        _, ok := m[v]
        if ok {
            m[v] = m[v] + 1
        } else {
            m[v] = 1
        }
    }
    return m
}

weixingongzhonghao

上一篇 [GO] stringer

下一篇 [GO] glog

Comments

Content