Please see below my map
var romanNumeralDict map[int]string = map[int]string{
1000: "M",
900 : "CM",
500 : "D",
400 : "CD",
100 : "C",
90 : "XC",
50 : "L",
40 : "XL",
10 : "X",
9 : "IX",
5 : "V",
4 : "IV",
1 : "I",
}
I am looking to loop through this map in the order of the size of the key
for k, v := range romanNumeralDict {
fmt.Println("k:", k, "v:", v)
}
However, this prints out
k: 1000 v: M
k: 40 v: XL
k: 5 v: V
k: 4 v: IV
k: 900 v: CM
k: 500 v: D
k: 400 v: CD
k: 100 v: C
k: 90 v: XC
k: 50 v: L
k: 10 v: X
k: 9 v: IX
k: 1 v: I
Is there a way that I can print them out in the order of the size of the key so, I would like to loop through this map like this
k:1
K:4
K:5
K:9
k:10
etc...
Thank you very much for your help!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…