# [Leet Code] Count Items Matching a Rule

`Input: items = [["phone","blue","pixel"],["computer","silver","lenovo"],["phone","gold","iphone"]], ruleKey = "color", ruleValue = "silver"Output: 1Explanation: There is only one item matching the given rule, which is ["computer","silver","lenovo"].`
`Input: items = [["phone","blue","pixel"],["computer","silver","phone"],["phone","gold","iphone"]], ruleKey = "type", ruleValue = "phone"Output: 2Explanation: There are only two items matching the given rule, which are ["phone","blue","pixel"] and ["phone","gold","iphone"]. Note that the item ["computer","silver","phone"] does not match.`
`class Solution(object):    def countMatches(self, items, ruleKey, ruleValue):        """        :type items: List[List[str]]        :type ruleKey: str        :type ruleValue: str        :rtype: int        """                dictionary = {"type": 0, "color": 1, "name" : 2}        indexPos = dictionary[ruleKey]        answer = 0                for i,v in enumerate(items):            if v[indexPos] == ruleValue:                answer += 1                return answer`

--

--

--

Learning, and posting my findings!

Love podcasts or audiobooks? Learn on the go with our new app.

## Matthew Boyd

Learning, and posting my findings!