...

/

Sorting and Inverting a Map

Sorting and Inverting a Map

This lesson covers important details on sorting and inverting a map.

Sorting a map

By default, a map is not sorted, not even on the value of its keys. If you want a sorted map, copy the keys (or values) to a slice, sort the slice (using the sort package), and print out the keys and/or values using the for-range on the slice. This is illustrated in the following program:

Access this course and 40+ top-rated courses and projects.