Last Updated: February 25, 2016
·
8.21K
· lukasz-madon

Count Words in Go

import ( "strings" ) 

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