-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmost.py
More file actions
28 lines (22 loc) · 706 Bytes
/
most.py
File metadata and controls
28 lines (22 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Using Dictionary
class Solution(object):
def mostCommonWord(self, paragraph, banned):
"""
:type paragraph: str
:type banned: List[str]
:rtype: str
"""
count = {}
for word in paragraph.strip().split(" "):
word = word.lower().strip(",.?!;':")
if word not in count:
count[word] = 0
count[word] += 1
maxi = 0
select = ""
for key, value in count.items():
if (value > maxi) and (key not in banned):
maxi = value
select = key
return select
# Todo ==> Try doing this without dictionary