Pair Keys with Values
Data often arrives as two separate lists: one with field names and another with their values. The function build_dict receives a list keys and a list values of the same length and combines them into a new dictionary. The first key should get the first value, the second key should get the second value, and so on by position.
Примеры
Ввод
(["a", "b", "c"], [1, 2, 3])Вывод
{"a": 1, "b": 2, "c": 3}Ввод
([], [])Вывод
{}Ввод
(["x"], [9])Вывод
{"x": 9}Нужно реализовать
def build_dict(keys: list, values: list) -> dict:
Теги
dictlistshashmap
Logi sisse, et näha esituste ajalugu
Logi sisseLogi sisse, et kasutada AI mentorit
Logi sisseVisible tests
1
Input
["a","b","c"], [1,2,3]Expected
{"a":1,"b":2,"c":3}2
Input
[], []Expected
{}3
Input
["x"], [9]Expected
{"x":9}4
Input
["k1","k2"], ["v1","v2"]Expected
{"k1":"v1","k2":"v2"}5
Input
["a","b"], [10,20]Expected
{"a":10,"b":20}6
Input
["p"], [0]Expected
{"p":0}Focus radio
Paused · SomaFM · Fluid