Tag

Go Tour 43

func WordCount(s string) map[string]int {
      words:=strings.Fields(s)
      m := make(map[string]int)
      for _,word:=range words {
         if _, ok:=m[word];ok{
             m[word]++
         else{
             m[word]=1
         }
     }
     return m
}
Iklan