Initialize a Dict by broadcasting

or

Dict(d => Float64[] for d in mydates)

is the best you can do.

The reason is:

  1. it is readable.
  2. it is correct.

The point about correctness is that you need to make sure that you allocate a fresh vector for each dictionary entry, and this is what comprehension does (that is why in the solution by @cgeoga also a comprehension had to be used)

You most likely wanted to write something like:

Dict(mydates .=> Ref(Vector{Float64}()))

unfortunately this would not be correct as dictionary values would be aliases.

4 Likes