exercise #40 in A Tour of Go My quick searching did not reveal anyone sharing their solution to this exercise, so am not sure if there are other (and better) approaches to mine:

package main

import (
    "code.google.com/p/go-tour/wc"
    "strings"
)

func WordCount(s string) map[string]int {
    foo := strings.Fields(s)
    m := make(map[string]int)
    for i := 0; i &lt; len(foo); i++ {
        v, ok := m[foo[i]]
        if ok {
            m[foo[i]] = v + 1
        }
        m[foo[i]] = v + 1
    }
    return m
}

func main() {
    wc.Test(WordCount)
}
You can be more concise and readable using range and the fact that the default value of the int is 0 :

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