-
Notifications
You must be signed in to change notification settings - Fork 8.6k
/
map_drinks.go
executable file
·74 lines (63 loc) · 1.24 KB
/
map_drinks.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// map_drinks.go
package main
import (
"fmt"
"sort"
)
func main() {
drinks := map[string]string{
"beer": "bière",
"wine": "vin",
"water": "eau",
"coffee": "café",
"thea": "thé"}
sdrinks := make([]string, len(drinks))
ix := 0
fmt.Printf("The following drinks are available:\n")
for eng := range drinks {
sdrinks[ix] = eng
ix++
fmt.Println(eng)
}
fmt.Println("")
for eng, fr := range drinks {
fmt.Printf("The french for %s is %s\n", eng, fr)
}
// SORTING:
fmt.Println("")
fmt.Println("Now the sorted output:")
sort.Strings(sdrinks)
fmt.Printf("The following sorted drinks are available:\n")
for _, eng := range sdrinks {
fmt.Println(eng)
}
fmt.Println("")
for _, eng := range sdrinks {
fmt.Printf("The french for %s is %s\n", eng, drinks[eng])
}
}
/* Output:
The following drinks are available:
wine
beer
water
coffee
thea
The french for wine is vin
The french for beer is bière
The french for water is eau
The french for coffee is café
The french for thea is thé
Now the sorted output:
The following sorted drinks are available:
beer
coffee
thea
water
wine
The french for beer is bière
The french for coffee is café
The french for thea is thé
The french for water is eau
The french for wine is vin
*/