Question: Question: Implement function duplicate() that takes as input the name (a string) of a file in the current directory and returns True if the file

Question:

Implement function duplicate() that takes as input the name (a string) of a file in the current directory and returns True if the file contains duplicate words and False otherwise.

>>> duplicate('Duplicates.txt')

True >>>

duplicate('noDuplicates.txt')

False

Notes:

Please do not use dictionary function to solve!!

Here is what I have please add to it or edit it to make the entire module work.

def duplicate(filename): infile = open(filename, 'r') content = infile.read() infile.close() wordList = content.split()

for word in wordList: if (len(word)>1 and len(word)%2!=0): return True return False

Please test your module before replying because the module must satisfy the following exactly as shown:

>>> duplicate('Duplicates.txt') True >>> duplicate('Duplicates.txt')==True True >>> duplicate('Duplicates2.txt') True >>> duplicate('Duplicates2.txt')==True True >>> duplicate('noDuplicates.txt') False >>> duplicate('noDuplicates.txt')==False True

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!