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 characters

package main

import "fmt"

func main() {
	text := "This is a very long text. OK, maybe it is not that long after all."
	counter := make(map[string]int)
	for _, c := range text {
		//fmt.Printf("%v", string(c))
		if string(c) != " " {
			counter[string(c)]++
		}
	}

	fmt.Println(text)
	for char, count := range counter {
		fmt.Printf("%v: %v\n", char, count)
	}

}