-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcount items matching a rule.py
More file actions
18 lines (16 loc) · 980 Bytes
/
count items matching a rule.py
File metadata and controls
18 lines (16 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from typing import List
class Solution:
def countMatches(self, items: List[List[str]], ruleKey: str, ruleValue: str) -> int:
keys= {"type": 0, "color": 1, "name" : 2 }
index = keys[ruleKey]
count = 0
for i in items:
if i[index] == ruleValue:
count +=1
return count
s= Solution()
print(s.countMatches([["phone","blue","pixel"],["computer","silver","lenovo"],["phone","gold","iphone"]], "color", "silver"))
print(s.countMatches([["phone","blue","pixel"],["computer","silver","lenovo"],["phone","gold","iphone"]], "type", "phone"))
print(s.countMatches([["phone","blue","pixel"],["computer","silver","lenovo"],["phone","gold","iphone"]], "name", "pixel"))
print(s.countMatches([["phone","blue","pixel"],["computer","silver","lenovo"],["phone","gold","iphone"]], "color", "blue"))
print(s.countMatches([["phone","blue","pixel"],["computer","silver","lenovo "],["phone","gold","iphone"]], "type", "computer"))