// Sorted Iteration
// Go maps are unordered, we sort the keys manually
package main
import (
"fmt"
"sort"
)
func main() {
dict := map[string]int{
"Bob": 17,
"Alice": 10,
"Marley": 23,
"Charlie": 36,
}
keys := make([]string, 0, len(dict))
for key := range dict {
keys = append(keys, key)
}
sort.Strings(keys)
for _, key := range keys {
fmt.Println(key, dict[key])
}
}
/*
run:
Alice 10
Bob 17
Charlie 36
Marley 23
*/