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

Exercise: count characters - sort by frequency

  • Given a string count how many time each character appears and list them by frequency.
  • Make the count case-insensitive (so "T" and "t" will count as the same letter.)
package main

import (
	"fmt"
)

func main() {
	text := "This is a very long text. OK, maybe it is not that long after all."
	fmt.Println(text)

}

Expected output:

This is a very long text. OK, maybe it is not that long after all.
s: 3
r: 2
l: 4
n: 3
x: 1
.: 2
m: 1
h: 2
b: 1
v: 1
t: 7
T: 1
e: 4
o: 3
O: 1
K: 1
,: 1
a: 5
y: 2
g: 2
f: 1
i: 4