I wrote some code which does this, and it is working fine, but when reviewing the code I realize what I did might not have worked in other languages.
To give a contrived example:
dict := map[string]string{ "a": "1", "b": "2" }
for key, val := range dict {
fmt.Println(val)
delete(dict, "b")
}
This prints "1" and "2", and when I inspect dict
afterward it is { "a": "1" }
only.
So, I get the impression that it is safe to do this, but I'm wondering why?
Does range dict
create a copy internally?