Since this is a common procedure when counting items in sequences, there is 
a specialized function (`merge`) and data structure (`Accumulator`) for it 
in the package `DataStructures`. Try a version of the following:


   using DataStructures
   a = Dict(2 => 5, 3 => 7, 5 => 1)
       b = Dict(2 => 3, 3 => 5, 11 => 4)
      c = Dict(merge(counter(a),counter(b))

 you can also look at the other Accumulator functions, which may be useful 
for what you are doing.

On Sunday, October 11, 2015 at 7:00:45 PM UTC+3, Grey Marsh wrote:
>
> Hello,
>
> How do I merge two a = Dict(2 => 5, 3 => 7, 5 => 1), b = Dict(2 => 3, 3 => 
> 5, 11 => 4). I need to merge these two to a dict in which the values for 
> common keys are added up. In case of the dicts a and b it would give c = 
> Dict(2 => 8, 3 => 12, 5 => 1, 11 => 4). If I do merge(a,b) it gives be 
> key:value from the last dict with any unique key:values being replicated.
>
> Any help would be appreciated.
>

Reply via email to