[Java/Python 3] Map.
java\n    private static final Map<String, Integer> rule = Map.of("type", 0, "color", 1, "name", 2);\n    public int countMatches(List<List<String>> items, Stri
```java\n    private static final Map<String, Integer> rule = Map.of("type", 0, "color", 1, "name", 2);\n    public int countMatches(List<List<String>> items, String ruleKey, String ruleValue) {\n        int cnt = 0, index = rule.get(ruleKey);\n        for (List<String> item : items) {\n            if (item.get(index).equals(ruleValue)) {\n                ++cnt;\n            }\n        }\n        return cnt;\n    }\n```\n```python\n    rule = {\'type\' : 0, \'color\' : 1, \'name\' : 2}\n    def countMatches(self, items: List[List[str]], ruleKey: str, ruleValue: str) -> int:\n        cnt, index = 0, self.rule[ruleKey]\n        for item in items:\n            if item[index] == ruleValue:\n                cnt += 1\n        return cnt\n```\nor make them shorter:\n**java 8**\n```java\n    private static final Map<String, Integer> rule = Map.of("type", 0, "color", 1, "name", 2);\n    public int countMatches(List<List<String>> items, String ruleKey, String ruleValue) {\n        return (int)items.stream()\n                         .filter(item -> item.get(rule.get(ruleKey)).equals(ruleValue))\n                         .count();\n    }\n```\nPython 3 code -- credit to **@SunnyvaleCA**.\n```python\n    rule = {\'type\' : 0, \'color\' : 1, \'name\' : 2}\n    def countMatches(self, items: List[List[str]], ruleKey: str, ruleValue: str) -> int:\n        return sum(1 for item in items if item[self.rule[ruleKey]] == ruleValue)\n```
[]