logo CodeStepByStep logo


Language/Type: Python file input

Write a function named remove_duplicates_from_file that accepts a string representing a file name as its parameter, and opens that file, reading each word in it and printing that word with its duplicate letters removed. For example, if the file myinput.txt contains the following text:

tresssssidder union
iisss hiiirriingg a
neeew bookkeeper !!!!

tteehhh  eeend. 

Then the call of remove_duplicates_from_file("myinput.txt") should print the following console output:

tresider union 
is hiring a 

new bokeper ! 

teh end.

Notice that the duplicate characters have been removed from each word in the file, retaining the given line breaks that were present in the file originally. You may assume that the given file exists and is readable. You may also assume that each word on each line of the file is separated by a single space.

Note: You may want to go solve the string problem remove_duplicates first and then paste its solution here so that you can call it as a helper to solve this problem. You can submit both functions in your solution, one after the other.

Function: Write a Python function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.