Exercise : Map

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)