Question: IN PYTHON CODE Question #1 a) Question #1 b) This question is similar ify your code from the previous question for this one. Write a

IN PYTHON CODE IN PYTHON CODE Question #1 a) Question #1 b) This question

Question #1 a) Question #1 b) This question is similar ify your code from the previous question for this one. Write a function long-words that has one argument: file.name that is a string that is the name of a text file. The file will consist of a nuber flines of text, and each line will consist of a number of strings, separated by one or more space characters. The command long.words (file.name) should return a set that contains all of the longest words that are obtained from strings found in the file to the previous one and you should be able to mod Write a function long-strings that has one argument: file.name that is a string that is the name of a text file. The file will consist of a number of lines of text, and each line will consist of a number of strings, separated by one or more space characters. The command long-strings(file name) should return a set that contains all of the longest strings that are found in the file. Note that the strings found in the lines of the file may consist of any non whitespace characters, including letters, digits, and punctuation symbols. If the file only consists of lines that contain spaces, t return the empty set hen the function should For the purposes of this exercise, a word is obtained from a string by stripping away any trailing punctuation symbols, as long as the only re- maining characters are alphabetic, upper or lower case. For example, after stripping away the trailing punctuation symbols the string "aBc!$,?" gives rise to the word "aBc". Since the string "$a,blc??" contains non-alphabetic mapped to thecharacters, even after stripping away the trailing punctuation symbols, then If there is a third arg, !ument, it does not give rise to a word in this sense. If the file only consists of lines For example, if the file question.1.txt consists of the following five lines of text If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character!! in x vill be chAracters at the same #positi on! in y it must be a string, vhose characters will be mapped to None in the result. that contain spaces or does not contain any words, then the function should return the empty set. then long-strings" question.! . txt , ) should return the set (' #posit Xon ! , , For example, long-words('question.1.txt should return the set 'chAracters 'characters', 'dictionary, where the file question1.txt is from the previous question. This is because both of these words were ob- tained by stripping away any trailing punctuation symbols from strings found in the file and no other words obtained from the file are longer than these three. You should consider strings that consists of the same sequence of let- ters, but with different capitalizations, to be different words. For example, in the test file, the words characters and chAracters should both appear in the set. arg, lument,', 'character!!', 'dictionary, '], since each of the strings in this set have length 11 and no string in the file has a longer length. To test your code on the file question.1.txt you can download it here: https://ms.master.ca/matt/mp3/homework/question-1.txt. Be sure that this file, or any other text file that you test your code on is located in the same folder/directory as your jupyter notebook or python code. Your code should close any files that it open s before returning any values. Hint: You will probably want to use the string functions .stripO and split) to help identify the strings in the file that should be considered. To test your code on the file question.1.txt you can download it here: https://ms.mcmaster.ca/ matt/1mp3/homework/question 1.txt. Be sure that this file, or any other text file that you test your code on is located in the same folder/directory as your jupyter notebook or python code Hint: You should consider using the string string.punctuation. It consists of all of the punctuation characters recognized by python

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!