Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Solution: count words

package main

import (
	"fmt"
	"strings"
)

func main() {
	var count = make(map[string]int)
	var text = "hello world how are you world and how are you"
	//fmt.Println(text)

	var words = strings.Split(text, " ")
	//fmt.Println(words)
	for _, word := range words {
		count[word]++
	}
	//fmt.Println(count)

	for k, v := range count {
		fmt.Printf("%s: %d\n", k, v)
	}

}