'''
https://leetcode.com/problems/most-common-word/description/
2018/07
28 ms
'''

import re

class Solution(object):
    def mostCommonWord(self, paragraph, banned):
        """
        :type paragraph: str
        :type banned: List[str]
        :rtype: str
        """
        freqs = {}
        words = map(lambda s: s.lower(), re.compile(' |\!|\?|\'|,|;|\.').split(paragraph))
        #print words
        for w in words:
            if w in freqs:
                freqs[w] += 1
            else:
                freqs[w] = 1
        count = 0
        common = ''
        for w in freqs:
            if w in banned or len(w) < 1:
                continue
            if freqs[w] > count:
                count = freqs[w]
                common = w
        return common
