def printName(): print("Sarah Diesburg") 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) def countTimes(textFile): # Get the big word list wordList = createWordList(textFile) # New dictionary newDict = {} for word in wordList: #If not in dictionary if not word in newDict: newDict[word] = 1 else: newDict[word] += 1 # Print dictionary in alphabetical order # Get a list of the keys sortList = [] for key,value in newDict.items(): sortList.append((value,key)) sortList.sort(reverse=True) for myTup in sortList: print(myTup[1], "->", myTup[0])