if is already in countsadd one to the count for elseset count for to this decision ensures that the first time word is encounteredit will be entered into the dictionary with count of one way to implement this decision is to use the in operator if in countscounts[wcounts[ elsecounts[ more elegant approach is to use the get method counts[wcounts get( , if is not already in the dictionarythis get will return and the result is that the entry for is set to the dictionary updating code will form the heart of our program we just need to fill in the parts around it the first task is to split our text document into sequence of words in the processwe will also convert all the text to lowercase (so occurrences of "foomatch "foo"and eliminate punctuation (so "foo,matches "foo"here' the code to do thatfname input("file to analyze"read file as one long string text open(fname," "read(convert all letters to lower case text text lower(replace each punctuation character with space for ch in '!"#$%&()*+,/:;?@[\\]^ '{|}~'text text replace(ch"split string at whitespace to form list of words words text split(now we can easily loop through the words to build the counts dictionary counts {for in wordscounts[wcounts get( ,