<reponame>klee30810/TIL_CS<gh_stars>1-10
"""
Creater : <NAME>
Updated at : 210918
Reference : leetcode 819
"""
import re
from collections import defaultdict

paragraph = "Bot hit a ball, the hit BALL flew far after it was hit."
banned = ["hit"]

def most_common_word(s: str, ban:str ) -> str:

    # erase special cases, lower & split
    words = [word for word in re.sub(pattern=r'[^\w]',repl=' ',string=paragraph).lower().split() if word not in ban]

    # count up frequencies of the word
    counts = defaultdict(int)
    for word in words:
        counts[word] += 1

    return max(counts, key=counts.get)

print(most_common_word(s=paragraph, ban=banned))
# most_common_word(paragraph)
"""
Creater : <NAME>
Updated at : 210918
Reference : leetcode 819
"""
import re
from collections import defaultdict

paragraph = "Bot hit a ball, the hit BALL flew far after it was hit."
banned = ["hit"]

def most_common_word(s: str, ban:str ) -> str:

    # erase special cases, lower & split
    words = [word for word in re.sub(pattern=r'[^\w]',repl=' ',string=paragraph).lower().split() if word not in ban]

    # count up frequencies of the word
    counts = defaultdict(int)
    for word in words:
        counts[word] += 1

    return max(counts, key=counts.get)

print(most_common_word(s=paragraph, ban=banned))
# most_common_word(paragraph)
Creater : <NAME> Updated at : 210918 Reference : leetcode 819 # erase special cases, lower & split # count up frequencies of the word # most_common_word(paragraph)