Merge Totals
This operation is common in statistics, such as combining sales or views from two sources. Write a function merge_sum that receives two dictionaries with numeric values and returns a new merged dictionary. If a key appears in both dictionaries, add its values together. If a key appears in only one dictionary, copy that value into the result.
Примеры
Ввод
{"a": 1, "b": 2}, {"b": 3, "c": 4}Вывод
{"a": 1, "b": 5, "c": 4}Ввод
{}, {}Вывод
{}Ввод
{"x": 1}, {}Вывод
{"x": 1}Нужно реализовать
def merge_sum(a: dict, b: dict) -> dict:
Теги
dicthashmap
Accedi per vedere la cronologia degli invii
AccediAccedi per usare l'AI Mentor
AccediVisible tests
1
Input
{"a":1,"b":2}, {"b":3,"c":4}Expected
{"a":1,"b":5,"c":4}2
Input
{}, {}Expected
{}3
Input
{"x":1}, {}Expected
{"x":1}4
Input
{}, {"y":2}Expected
{"y":2}5
Input
{"a":5}, {"a":5}Expected
{"a":10}6
Input
{"p":1,"q":2}, {"q":2,"r":3}Expected
{"p":1,"q":4,"r":3}Focus radio
Paused · SomaFM · Fluid