2016-03-26 3 views

ответ

7

http://docs.julialang.org/en/latest/stdlib/collections/#Base.Dict

merge(collection, others...) 

Construct a merged collection from the given collections. If necessary, the types of the resulting collection will be promoted to accommodate the types of the merged collections. If the same key is present in another collection, the value for that key will be the value it has in the last collection listed. 

julia> merge(dict1,dict2) 
    Dict{ASCIIString,Int64} with 6 entries: 
     "f" => 6 
     "c" => 3 
     "e" => 5 
     "b" => 2 
     "a" => 1 
     "d" => 4 

merge!(collection, others...) 
Update collection with pairs from the other collections. 

julia> merge!(dict1,dict2) 
Dict{ASCIIString,Int64} with 6 entries: 
    "f" => 6 
    "c" => 3 
    "e" => 5 
    "b" => 2 
    "a" => 1 
    "d" => 4 

julia> dict1 
Dict{ASCIIString,Int64} with 6 entries: 
    "f" => 6 
    "c" => 3 
    "e" => 5 
    "b" => 2 
    "a" => 1 
    "d" => 4 
+1

Просто из любопытства, если, как бы, таким образом, обрабатывать конфликтующие ключевые ценности? Если у меня есть значения «a = 5» в «dict1» и «a = 7» в «dict2», каково значение «a» в результирующем словаре? – niczky12

+1

@ niczky12 будет обновлено до 7, последнее значение. –

+1

Если вы хотите сохранить противоречивые значения, вы можете использовать 'union (dict1, dict2)'; однако это вернет «Массив», а не «Дикт». –

Смежные вопросы