Kodewick
Start learning →
Basic←0 / 3

Letter tally

#003BasicMapsStrings4 min

Write Tally(word) to return a map of how many times each character (spaces too) appears.

Examples
Tally("pop")→{'o': 1, 'p': 2}
Tally("")→{}
The functionfunc Tally(word string) map[string]int
main.go
package main

func Tally(word string) map[string]int {
	count := map[string]int{}
	for _, r := range word {
		// your code here: add 1 to this character's count (the key: string(r))
	}
	return count
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.