819. Most Common Word
All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : September 24, 2024
Last updated : September 24, 2024
Related Topics : Array, Hash Table, String, Counting
Acceptance Rate : 44.39 %
class Solution:
def mostCommonWord(self, paragraph: str, banned: List[str]) -> str:
cnt = Counter([x.lower() for x in re.findall('[A-Za-z]+', paragraph)])
banned = set(banned)
output = sorted([x for x in cnt.keys() if x not in banned], key=lambda x: cnt[x])
return output[-1]