Merge Counts
Dictionaries are often used for counting, such as products sold by category or points earned by players. Write a function merge_sum that receives two dictionaries a and b with numeric values and merges them into a new dictionary. If a key appears in both dictionaries, add the values together. If a key appears in only one dictionary, copy its value into the result.
Примеры
Ввод
{"x": 1, "y": 2}, {"y": 3, "z": 4}Вывод
{"x": 1, "y": 5, "z": 4}Ввод
{}, {"a": 1}Вывод
{"a": 1}Ввод
{"a": 1}, {}Вывод
{"a": 1}Нужно реализовать
def merge_sum(a: dict, b: dict) -> dict:
Теги
dicthashmap
Logi sisse, et näha esituste ajalugu
Logi sisseLogi sisse, et kasutada AI mentorit
Logi sisseVisible tests
1
Input
{"x":1,"y":2}, {"y":3,"z":4}Expected
{"x":1,"y":5,"z":4}2
Input
{}, {"a":1}Expected
{"a":1}3
Input
{"a":1}, {}Expected
{"a":1}4
Input
{"a":1,"b":2}, {"a":10,"b":20}Expected
{"a":11,"b":22}5
Input
{}, {}Expected
{}6
Input
{}, {"a":10,"b":20}Expected
{"a":10,"b":20}Focus radio
Paused · SomaFM · Fluid