In [20]:
from bs4 import BeautifulSoup  # For processing XMLfrom BeautifulSoup
import nltk
import re
import string

In [11]:
doc = open('garden-party.md').read()

In [14]:
words = nltk.word_tokenize(doc)

In [25]:
nopunct = [word for word in words if word not in string.punctuation]

In [44]:
def cleanWords(words): 
    nopunct = [word for word in words if word not in string.punctuation]
    lower = [word.lower() for word in nopunct]
    return lower

In [46]:
cleanwords = cleanWords(words)

In [52]:
counter = 0
for word in cleanwords: 
    if word == 'yes':
        counter+=1
print(counter)


13

In [53]:
t = nltk.Text(cleanwords)

In [55]:
t.concordance('yes')


Displaying 13 of 13 matches:
rybody is certain of knowing hundreds yes literally hundreds had come out in a 
elephone old girl '' the telephone `` yes yes oh yes kitty good morning dear co
hone old girl '' the telephone `` yes yes oh yes kitty good morning dear come t
d girl '' the telephone `` yes yes oh yes kitty good morning dear come to lunch
meringue-shells and what 's left over yes is n't it a perfect morning your whit
 's quite right '' she said calmly `` yes i ordered them are n't they lovely ''
d lemon-curd have you done that '' `` yes '' `` egg and— '' mrs. sheridan held 
id laura looking over her shoulder `` yes of course olive what a horrible combi
 should n't we '' laura had to say `` yes '' to that but she felt it was all wr
have some fresh coffee i 'm exhausted yes it 's been very successful but oh the
e pale sky and all she thought was `` yes it was the most successful party '' n
the shadow `` is that you laura '' `` yes '' `` mother was getting anxious was 
etting anxious was it all right '' `` yes quite oh laurie '' she took his arm s

In [ ]: