def createWordList(textFile): #Open the input file myFile = open(textFile,"r") #Read the file fileText = myFile.read() #Close the file myFile.close() #Clean up the test badChars = ".,!?;(){}:" for badChar in badChars: fileText=fileText.replace(badChar,"") #Deal with the dash fileText = fileText.replace("-"," ") #Lowercase all words fileText = fileText.lower() listOfWords = fileText.split() return(listOfWords) def countUniqueWords(textFile): # Get the big word list wordList = createWordList(textFile) # Unique word list uniqueWordList = [] for word in wordList: #If not in unique list if not word in uniqueWordList: uniqueWordList.append(word) return len(uniqueWordList)