-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.go
executable file
·46 lines (41 loc) · 809 Bytes
/
map.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
package main
import "fmt"
var print = fmt.Println
func test1() {
people := make(map[string]int)
people["Kevin"] = 46
people["Magnus"] = 6
people["Thor"] = 4
people["Amy"] = 42
print(people)
//print(people.keys())
age, ok := people["Kevin"]
print(age, ok)
age, ok = people["Fred"]
print(age, ok)
if age, ok = people["Magnus"]; ok {
print(age)
}
for key, val := range people {
print(key, val)
}
}
func testDeleteWhileIterating() {
people := make(map[string]int)
people["Amy"] = 42
people["Kevin"] = 46
people["Thor"] = 4
people["Magnus"] = 6
for key, value := range people {
print(key, value)
delete(people, key)
}
print("---")
fmt.Println("map len is now", len(people))
for key, value := range people {
print(key, value)
}
}
func main() {
testDeleteWhileIterating()
}