Course of Raku / Addendum 🆕 / Working with data / Text and strings / Exercises

Word frequency

Problem

Count how often each word appears in the sentence the cat sat on the mat the cat. Print one line per word as word: count, ordered by count from highest to lowest, and alphabetically when counts are equal.

Example

The program prints:

the: 3
cat: 2
mat: 1
on: 1
sat: 1

Solution

See the solution

Course navigation

Solution: Palindrome check   |   Solution: Word frequency