Catalog Rule Match
Imagine a simple product catalog filter where you need to count how many items match a chosen rule. Write a function count_matches where each item is a list of three strings: type, color, and name. The rule_key is one of "type", "color", or "name", and rule_value is the value to match. Return the number of items whose selected field equals rule_value.
Примеры
Ввод
[["phone", "blue", "pixel"], ["computer", "silver", "lenovo"], ["phone", "gold", "iphone"]], "color", "silver"Вывод
1Ввод
[["phone", "blue", "pixel"], ["phone", "gold", "iphone"]], "type", "phone"Вывод
2Ввод
[["a", "b", "c"]], "name", "c"Вывод
1Нужно реализовать
def count_matches(items: list[list[str]], rule_key: str, rule_value: str) -> int:
Теги
arraystrings
Kirjaudu sisään nähdäksesi palautushistorian
Kirjaudu sisäänKirjaudu sisään käyttääksesi tekoälymentoria
Kirjaudu sisäänTests12
Visible tests
Piilotettu testi 7
Piilotettu testi 8
Piilotettu testi 9
Piilotettu testi 10
Piilotettu testi 11
Piilotettu testi 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