Combine Settings

Dictionaries are often used for settings: first you have default values, then user choices can override them. The function merge_dicts receives two dictionaries, a and b, and combines them into a new dictionary. If the same key appears in both dictionaries, use the value from b.

Примеры

Ввод
({"x": 1}, {"y": 2})
Вывод
{"x": 1, "y": 2}
Ввод
({"x": 1}, {"x": 5})
Вывод
{"x": 5}
Ввод
({}, {})
Вывод
{}

Нужно реализовать

def merge_dicts(a: dict, b: dict) -> dict:

Теги

dicthashmap
PostgreSQLv16

Εδώ θα εμφανιστεί το αποτέλεσμα εκτέλεσης του κώδικα

Visible tests
1
Input
{"x":1}, {"y":2}
Expected{"x":1,"y":2}
2
Input
{"x":1}, {"x":5}
Expected{"x":5}
3
Input
{}, {}
Expected{}
4
Input
{"a":1,"b":2}, {"b":3,"c":4}
Expected{"a":1,"b":3,"c":4}
5
Input
{"k":0}, {}
Expected{"k":0}
6
Input
{}, {"y":2}
Expected{"y":2}
Focus radio
Paused · SomaFM · Fluid