advanced text parsing in the above example using the file romeo txtwe made the file as simple as possible by removing all punctuation by hand the actual text has lots of punctuationas shown below butsoftwhat light through yonder window breaksit is the eastand juliet is the sun arisefair sunand kill the envious moonwho is already sick and pale with griefsince the python split function looks for spaces and treats words as tokens separated by spaceswe would treat the words "soft!and "softas different words and create separate dictionary entry for each word also since the file has capitalizationwe would treat "whoand "whoas different words with different counts we can solve both these problems by using the string methods lowerpunctuationand translate the translate is the most subtle of the methods here is the documentation for translateline translate(str maketrans(fromstrtostrdeletestr)replace the characters in fromstr with the character in the same position in tostr and delete all characters that are in deletestr the fromstr and tostr can be empty strings and the deletestr parameter can be omitted we will not specify the tostr but we will use the deletestr parameter to delete all of the punctuation we will even let python tell us the list of characters that it considers "punctuation"import string string punctuation '!"#$%&\'()*+,/:;?@[\\]^ `{|}~the parameters used by translate were different in python we make the following modifications to our programimport string fname input('enter the file name'tryfhand open(fnameexceptprint('file cannot be opened:'fnameexit(counts dict(for line in fhandline line rstrip(