Collect all keys, sort them and iterate your map by key, like the following:
keys := make([]int, 0)
for k, _ := range romanNumeralDict {
keys = append(keys, k)
}
sort.Ints(keys)
for _, k := range keys {
fmt.Println(k, romanNumeralDict[k])
}
More Related Contents:
- Create a generic channel
- How to pipe several commands in Go?
- How to use a module that is outside of “GOPATH” in another module?
- slice of struct != slice of interface it implements?
- How can I convert string to integer in golang
- How to dump goroutine stacktraces?
- Does Go compiler’s evaluation differ for constant expression and other expression
- Cyclic dependencies and interfaces
- Accessing struct fields inside a map value (without copying)
- Why do I get a “cannot assign” error when setting value to a struct as a value in a map? [duplicate]
- Can I concurrently write different slice elements
- Organize local code in packages using Go modules
- Golang Dependency Management Best Practice
- How to compare if two structs, slices or maps are equal?
- Golang defer behavior
- Stack vs heap allocation of structs in Go, and how they relate to garbage collection
- Terminating function execution if a context is cancelled
- Conversion of time.Duration type microseconds value to milliseconds
- How to delete an element from a Slice in Golang
- Does the Go language have function/method overloading?
- Go: panic: runtime error: invalid memory address or nil pointer dereference
- How do I compare two functions for pointer equality in the latest Go weekly?
- Go struct tags with underscore before function names
- Function declaration syntax: things in parenthesis before function name
- How to import local packages without gopath
- How can I open files relative to my GOPATH?
- Difference between any/interface{} as constraint vs. type of argument?
- Streaming commands output progress
- Slice chunking in Go
- Handle maps with same key type but different value type