 <p>I thank you all for the input. I was able to fix my errors. I re-iterate through each character and strip the punctuation and i kept creating new lists to add repeated words then keep a single occurrence. The response that I have seem to work but I was not introduced to the higher order programming as yet.</p> <p>Here is the modified code:</p> <pre><code>def repeatWords(filename_1, filename_2): infile_1=open(filename_1,'r') content_1=infile_1.read() infile_1.close() import string new_content="" for char in content_1: new_content+=char.strip(string.punctuation) new_content=new_content.lower() new_content=new_content.split() repeated_list=[] for word in new_content: if new_content.count(word)&gt;1: repeated_list.append(word) new_repeat_list=[] for item in repeated_list: while item not in new_repeat_list: new_repeat_list.append(item) outfile=open(filename_2,'w') for repeat in new_repeat_list: outfile.write(repeat) outfile.write('\n') outfile.close() infile_2=open(filename_2,'r') content_2=infile_2.read() infile_2.close() return content_2 inF = 'catInTheHat.txt' outF = 'catRepWords.txt' print(repeatWords(inF, outF)) </code></pre>