Comment by lenkite
13 hours ago
> Also, if the map has arrays as elements, it will magically create one, like Python's defaultdict.
Err, no Go doesn't do that. No insertion happens unless you explicitly assign to the key.
13 hours ago
> Also, if the map has arrays as elements, it will magically create one, like Python's defaultdict.
Err, no Go doesn't do that. No insertion happens unless you explicitly assign to the key.
You're right. But it will return something: https://go.dev/play/p/Cz6aeGpURgo
prints `map[123:[456]]`
I guess it's convenient compared to Rust's strict approach with entry API. But also, what I found is that golang's subscript returns nil in one case: if the value type is a nested map.
output:
You can test for existence:
https://go.dev/blog/maps#working-with-maps
It returns the zero value for all types, including arrays (which is nil).
nil is equivalent to the empty array, which is why the rest of the code works as it does.