Imperative & procedural programming: statements, loops, mutation, procedures
#Go is a deliberately imperative, procedural language: functions, for loops (the only loop keyword), assignment and explicit error returns, with no classes and few functional helpers. A map lookup of a missing key yields the zero value, which makes accumulator loops short.
Complete program
Complete program.
In practice: write the plain loop; it is idiomatic Go, not a lack of style. Return new values from functions rather than updating package-level variables. Sort map keys before printing, because map iteration order is randomised.
Ranging over a map visits keys in a different order on each run; slices.Sorted(maps.Keys(m)) gives a stable order.
A map is a reference to shared storage: a function that writes into a map it received changes the caller's map too.