#Import Story
text = open('./alice.txt', 'rb').read()
#Split the text into individual words
def split_text(text):
#Import known words index
index = open('./words.dat', 'rb').read().split()
index_file = open('./words.dat','wb+')
for word in index:
index_file.write(word)
index_file.write('\n')
import string
#Remove punctuation
out = "".join(c for c in text if c not in string.punctuation).lower()
# split the text
words = out.split()
# for each word in the text:
word_count = 0
for word in words:
if word.endswith('.') or word.endswith(',') or word.endswith('"') or word.endswith('”'):
word = word[:-1]
if word not in index:
index.append(word)
index_file.write(word)
index_file.write('\n')
word_count = word_count + 1
print ('The total amount of new words is:')
print (word_count)
index_file.close()
split_text(text)
I keep getting an error on the "out =" line, "TypeError: 'in ' requires string as left operand" error