Исходники и презентации
This commit is contained in:
17
lessons/maps/delete_during_iteration/main.go
Normal file
17
lessons/maps/delete_during_iteration/main.go
Normal file
@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
data := map[string]int{"foo": 0, "bar": 1, "baz": 2}
|
||||
for key := range data {
|
||||
if key == "foo" {
|
||||
delete(data, "bar")
|
||||
}
|
||||
if key == "bar" {
|
||||
delete(data, "foo")
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println(data)
|
||||
}
|
||||
Reference in New Issue
Block a user