Question: Write a Python function, fconcordance with one parameter, fname, a string which is the name of a text file. fconcordance will return a concordance for

 Write a Python function, fconcordance with one parameter, fname, a stringwhich is the name of a text file. fconcordance will return aconcordance for file fname. A concordance is an index of the words

Write a Python function, fconcordance with one parameter, fname, a string which is the name of a text file. fconcordance will return a concordance for file fname. A concordance is an index of the words in the file, with each line(s) of the file where the word appears. A main function will call fconcordance and report the results. For example, for file tinyf.txt: Hello, World, hello. >>> fconcordance ('tinyf.txt') 'hello' occurs in lines: [1, 3] 'world' occurs in lines: [2] Note that case and punctuation are ignored when counting occurrences of a word (but see "Optional and Optimal"). Newline characters are also ignored. Include code in your .py file to call the main function. Write a Python function, fconcordance with one parameter, fname, a string which is the name of a text file. fconcordance will return a concordance for file fname. A concordance is an index of the words in the file, with each line(s) of the file where the word appears. A main function will call fconcordance and report the results. For example, for file tinyf.txt: Hello, World, hello. >>> fconcordance ('tinyf.txt') 'hello' occurs in lines: [1, 3] 'world' occurs in lines: [2] Note that case and punctuation are ignored when counting occurrences of a word (but see "Optional and Optimal"). Newline characters are also ignored. Include code in your .py file to call the main function. The string methods split, strip, and rstrip that we discussed in class this week will be helpful. Again, you might also explore punctuation from the string module from the Python Standard Library: >>> import string >>> string.punctuation "!"#$%&'()*+,-./:;?@[\\]^_{1}~! (Note that punctuation is a variable name, not a function.) Data structures are important. Consider what data structure would be best for a concordance. Hint: try a dictionary. Optional and Optimal Though we are ignoring case and punctuation in fconcordance, it would be nice to have flexibility about this. Add two default parameters (see discussion about default parameters in the showMonte Pi project specification), case and punc, to fconcordance. The parameters will be False by default, and case and punctuation will be ignored when comparing words. But if fconcordance is called with case=True, then case should be considered when comparing words. Similarly, if fconcordance is called with punc=True, then punctuation should be considered when comparing words

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!