In this lecture, we will look at how to produce deterministic, stable output in
Go: why iterating over a
map with
range does not guarantee order, how to get predictable output with “keys → sort → print”, how to sort simple keys with the
sort package (
sort.Strings,
sort.Ints), how to define your own order with
sort.Slice, and how to use the modern
slices package (
slices.Sort and
slices.SortFunc). We will also discuss a
tie-breaker for equal elements and the typical mistakes that make output “float” and break autograder tests.