How to implement in Go a function that pops a key from a map using just one lookup? This version does two lookups on the map:
package main
import "fmt"
func main() {
m := map[string]int{"a":1, "b":2}
a, ok := m["a"]
if ok {
delete(m, "a")
}
fmt.Println(a, m)
}
I checked maybe delete
returns the value of deleted key:
package main
func main() {
m := map[string]int{"a":1, "b":2}
println(delete(m, "a"))
}
But this doesn't work:
prog.go:5: delete(m, "a") used as value