-
Notifications
You must be signed in to change notification settings - Fork 247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DefaultDict accessor fails when the default is not the value type #901
Comments
FWIW, I don't understand why it calls |
By calling dict_of_lists = DefaultDict(Vector)
for (key, item) in (:a=>1, :b=>1, :a=>10)
push!(dict_of_lists[key], item)
end Which is very useful -- in my experience this kinda pattern of a collection of collections is the most common use for a DefaultDict I don't undestand there being heavy demand for if the default isn't the same type. |
What I missed is that whenever access falls back to the default, it is stored in the parent dict, as in julia> using DataStructures
julia> dd = DefaultDict(1, :a => 2)
DefaultDict{Symbol, Int64, Int64} with 1 entry:
:a => 2
julia> dd[:b]
1
julia> dd
DefaultDict{Symbol, Int64, Int64} with 2 entries:
:a => 2
:b => 1 I find this design somewhat surprising, as it just replicates From the docs it was my expectation that |
Yes, it replicates |
MWE:
The text was updated successfully, but these errors were encountered: