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
PostgreSQLv16

Hier verschijnt het resultaat van je code

Visible tests
1
Input
[["phone","blue","pixel"],["computer","silver","lenovo"],["phone","gold","iphone"]], "color", "silver"
Expected1
2
Input
[["phone","blue","pixel"],["phone","gold","iphone"]], "type", "phone"
Expected2
3
Input
[["a","b","c"]], "name", "c"
Expected1
4
Input
[], "type", "x"
Expected0
5
Input
[["t","red","n1"],["t","red","n2"]], "color", "red"
Expected2
6
Input
[["t","blue","n"]], "color", "red"
Expected0
Focus radio
Paused · SomaFM · Fluid