Understanding how nested defaultdict works

your last example is a scope issue, you’re losing the reference of the original x

julia> t=tree()
DefaultDict{Any, Any, typeof(tree)}()

julia> let x=t
           for i in [1,2,3]
               x=x[i]
           end
       end

julia> t
DefaultDict{Any, Any, typeof(tree)} with 1 entry:
  1 => DefaultDict{Any, Any, typeof(tree)}(2=>DefaultDict{Any, Any, typeof(tree)}(3=>…
1 Like