-
Notifications
You must be signed in to change notification settings - Fork 0
/
map1.go
41 lines (37 loc) · 891 Bytes
/
map1.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// the telephone alphabet:
package main
import (
"fmt"
"sort"
)
var (
barVal = map[string]int{"alpha": 1, "bravo": 2, "charlie": 3,
"delta": 4, "echo": 5, "foxtrot": 6,
"golf": 7, "hotel": 8, "indio": 9,
"juliet": 10, "kili": 11, "lima": 12}
)
func main() {
fmt.Println("*************:")
fmt.Println()
fmt.Println("map:", barVal)
fmt.Println()
fmt.Println("unsorted:")
fmt.Println()
for k, v := range barVal {
fmt.Printf("Key: %v, Value: %v / ", k, v)
}
keys := make([]string, len(barVal))
i := 0
for k := range barVal {
keys[i] = k
i++
}
sort.Strings(keys)
fmt.Println()
fmt.Println()
fmt.Println("sorted:")
fmt.Println()
for _, k := range keys {
fmt.Printf("Key: %v, Value: %v / ", k, barVal[k])
}
}