Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

25 Vba Macros For Data Analysis In Microsoft Excel

Authors: Klemens Nguyen

1st Edition

B0CNSXYMTC, 979-8868455629

More Books

Students also viewed these Databases questions