Isn't merge! already in the standard library?

On Sunday, July 27, 2014 11:24:36 AM UTC+1, Mike Innes wrote:
>
> Just in case it's useful here's a function which I use:
>
> function merge!(a::Dict, b::Dict)
>   for (k, v) in b
>     a[k] = v
>   end
>   return a
> end
>
> If you replace push! with merge! in your original example it should work 
> as expected.
>
>
> On 27 July 2014 01:11, John Myles White <[email protected] 
> <javascript:>> wrote:
>
>> You don’t push to Dict’s because they’re not ordered.
>>
>> You can add a entry using indexing:
>>
>> dc = Dict{UTF8String, Int64}()
>> dc["A."] = 2
>>
>>  — John
>>
>> On Jul 26, 2014, at 5:09 PM, Ben Ward <[email protected] <javascript:>> 
>> wrote:
>>
>> Is it possible to extend a dict with a key value pair?
>>
>> I don't see a method to do it in the standard library reference. There is 
>> a pop!, but I tried push! but it just produced an error. Perhaps I'm not 
>> doing it right.
>>
>> dc = Dict{String, Int64}()
>> push!(dc, ["A." => 2])
>>
>>
>> *Thanks,*
>>
>> *Ben.*
>>
>>
>>
>

Reply via email to