# Input
paragraph = 'Bob hit a ball, the hit BALL flew for after it was hit'
banned = ['hit']

# pre-cleaning
paragraph = paragraph.lower()
par = paragraph.split(',')
par1 = par[0].split()
par2 = par[1].split()
par = par1 + par2

# find common words
common = []
for word in par:
    count = 0
    for iter in par:
        if word == iter:
            count += 1
    if count >= 2:
        common.append(word)

# delete banned words
common = set(common)
common = list(common)
common

for ban in banned:
    for word in common:
        if word == ban:
            common.remove(word)

for res in common:
    print(res)


# Input
paragraph = 'Bob hit a ball, the hit BALL flew for after it was hit'
banned = ['hit']

# 1
import re
import collections

# pre-processing
words = [word for word in re.sub('[^\w]', ' ', paragraph).lower().split() if word not in banned]
counts = collections.Counter(words) # counts the number of words

counts.most_common(1)[0][0] # find the most common word

# 2
# defaultdict
counts = collections.defaultdict(int)
for word in words:
    counts[word] += 1

# argmax
max(counts, key=counts.get)

de43dad490f4a5bf87a205830edc97bbf18d0d25
<mask token>

<mask token>
for word in par:
    count = 0
    for iter in par:
        if word == iter:
            count += 1
    if count >= 2:
        common.append(word)
<mask token>
common
for ban in banned:
    for word in common:
        if word == ban:
            common.remove(word)
for res in common:
    print(res)
<mask token>
counts.most_common(1)[0][0]
<mask token>
for word in words:
    counts[word] += 1
max(counts, key=counts.get)

paragraph = 'Bob hit a ball, the hit BALL flew for after it was hit'
banned = ['hit']
paragraph = paragraph.lower()
par = paragraph.split(',')
par1 = par[0].split()
par2 = par[1].split()
par = par1 + par2
common = []
for word in par:
    count = 0
    for iter in par:
        if word == iter:
            count += 1
    if count >= 2:
        common.append(word)
common = set(common)
common = list(common)
common
for ban in banned:
    for word in common:
        if word == ban:
            common.remove(word)
for res in common:
    print(res)
paragraph = 'Bob hit a ball, the hit BALL flew for after it was hit'
banned = ['hit']
<mask token>
words = [word for word in re.sub('[^\\w]', ' ', paragraph).lower().split() if
    word not in banned]
counts = collections.Counter(words)
counts.most_common(1)[0][0]
counts = collections.defaultdict(int)
for word in words:
    counts[word] += 1
max(counts, key=counts.get)

paragraph = 'Bob hit a ball, the hit BALL flew for after it was hit'
banned = ['hit']
paragraph = paragraph.lower()
par = paragraph.split(',')
par1 = par[0].split()
par2 = par[1].split()
par = par1 + par2
common = []
for word in par:
    count = 0
    for iter in par:
        if word == iter:
            count += 1
    if count >= 2:
        common.append(word)
common = set(common)
common = list(common)
common
for ban in banned:
    for word in common:
        if word == ban:
            common.remove(word)
for res in common:
    print(res)
paragraph = 'Bob hit a ball, the hit BALL flew for after it was hit'
banned = ['hit']
import re
import collections
words = [word for word in re.sub('[^\\w]', ' ', paragraph).lower().split() if
    word not in banned]
counts = collections.Counter(words)
counts.most_common(1)[0][0]
counts = collections.defaultdict(int)
for word in words:
    counts[word] += 1
max(counts, key=counts.get)

# Input
paragraph = 'Bob hit a ball, the hit BALL flew for after it was hit'
banned = ['hit']

# pre-cleaning
paragraph = paragraph.lower()
par = paragraph.split(',')
par1 = par[0].split()
par2 = par[1].split()
par = par1 + par2

# find common words
common = []
for word in par:
    count = 0
    for iter in par:
        if word == iter:
            count += 1
    if count >= 2:
        common.append(word)

# delete banned words
common = set(common)
common = list(common)
common

for ban in banned:
    for word in common:
        if word == ban:
            common.remove(word)

for res in common:
    print(res)


# Input
paragraph = 'Bob hit a ball, the hit BALL flew for after it was hit'
banned = ['hit']

# 1
import re
import collections

# pre-processing
words = [word for word in re.sub('[^\w]', ' ', paragraph).lower().split() if word not in banned]
counts = collections.Counter(words) # counts the number of words

counts.most_common(1)[0][0] # find the most common word

# 2
# defaultdict
counts = collections.defaultdict(int)
for word in words:
    counts[word] += 1

# argmax
max(counts, key=counts.get)
