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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started