Write a function named repeatCount().
The function repeatCount() takes two string parameters:
--> the name of an input file and the name of an output file.
The function repeatCount() should read each line of the input file, identify the number of words on the line that occur more than once, and write that number to a line in the output file.
A word should be considered to be repeated if occurs with different capitalization.
That is, 'To' and 'to' are the same word.
You may assume that the file contains only upper and lower case letters and white space; it does not contain any punctuation marks.
For example, suppose the input file contains the following four lines:
Woke up this morning with an ache in my head
I splashed on my clothes as I spilled out of bed
I opened the window to listen to the news
But all I heard was the Establishment Blues
Then the output file should contain the following four lines:
0
1
2
0
Note: * 1: because I is the only letter that repeats in 2nd line and 2: because to , the are being repeated
0 indicates no words are being repeated*
Here is my code
def repeatCount(filename1, filename2):
inf = open(filename1, 'r')
outf = open(filename2, 'w')
aDict = {}
text = inf.read()
text = text.lower().split()
aDict = {}
for word in text:
aDict[word] = text.count(word)
for key in aDict:
outf.write(key + int(aDict[key]) + '\n')
aDict.count(key)
inf.close()
outf.close()
repeatCount("fourlines.txt", "outputLines.txt")
-- I am getting error --
outf.write(key + int(aDict[key]) + '\n')
TypeError: Can't convert 'int' object to str implicitly
Can someone help me with this code!!
Thank you.