Keep High Values
Filtering a dictionary is useful when you want to keep only important records, like products above a certain price or players with enough points. The function filter_dict_by_value receives a dictionary d and a number threshold. Return a new dictionary containing only the pairs whose value is at least threshold; smaller values should be left out.
Примеры
Ввод
({"a": 1, "b": 5, "c": 3}, 3)Вывод
{"b": 5, "c": 3}Ввод
({}, 0)Вывод
{}Ввод
({"x": 10}, 20)Вывод
{}Нужно реализовать
def filter_dict_by_value(d: dict, threshold: int) -> dict:
Теги
dict
Logáil isteach chun stair na n-aighneachtaí a fheiceáil
Logáil isteachLogáil isteach chun an Meantóir IS a úsáid
Logáil isteachTests12
Visible tests
Tástáil fholaithe 7
Tástáil fholaithe 8
Tástáil fholaithe 9
Tástáil fholaithe 10
Tástáil fholaithe 11
Tástáil fholaithe 12
They run when you press "Submit" — your whole solution is checked against them so you can't hard-code answers for the visible cases.
Focus radio
Paused · SomaFM · Fluid