hic003cih / Golang

0 stars 0 forks source link

练习:映射 #30

Open hic003cih opened 4 years ago

hic003cih commented 4 years ago
package main

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

func WordCount(s string) map[string]int {
        words = strings.Fields(s)

    m :=make([string] int)

    for _,word = range words {

        _,ok := m[word]

        if ok == false{
            m[word] = 1
        }else{
          m[word]++
        }
    }
    return map[string]int{"x": 1}
}

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