File tree Expand file tree Collapse file tree 2 files changed +10
-6
lines changed
Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -47,14 +47,18 @@ addresses are equal
4747var set map[string]struct{}
4848// Initialize the set
4949set = make(map[string]struct{})
50+
5051// Add some values to the set:
5152set["one"] = struct{}{}
5253set["two"] = struct{}{}
54+
5355// Check if a value is in the map:
54- A kind of , ok := set["one"]
56+
5557//output true
56- fmt.Println ("Is one in the map?", ok)
57- A kind of , ok = set["three"]
58+ _, ok := set["one"]
59+ fmt.Println("Is one in the map?", ok)
60+
5861//output false
59- fmt.Println ("Is three in the map?", ok)
62+ _, ok = set["three"]
63+ fmt.Println("Is three in the map?", ok)
6064```
Original file line number Diff line number Diff line change @@ -50,13 +50,13 @@ set["one"] = struct{}{}
5050set["two"] = struct{}{}
5151
5252// Check if a value is in the map:
53- _, ok := set["one"]
5453
5554//output true
55+ _, ok := set["one"]
5656fmt.Println("Is one in the map?", ok)
57- _, ok = set["three"]
5857
5958//output false
59+ _, ok = set["three"]
6060fmt.Println("Is three in the map?", ok)
6161```
6262
You can’t perform that action at this time.
0 commit comments