Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4. (8 pts) Write a function named multi compare, that takes three open files as arguments: the first file contains some number of regular expression

image text in transcribed

4. (8 pts) Write a function named multi compare, that takes three open files as arguments: the first file contains some number of regular expression patterns, the second and third files contain some number of lines of text. This function returns a list of 3-tuples. Each returned 3-tuple represents a line number and one line from each file (the one with that line number), for which the line from the first file matched different patterns than the line from the second file. The list should show these line numbers in ascending order (which can be done without sorting) There are many ways to solve this problem. Hints: Read each file only once (remember to call rstrip for each line). Call re.compile to compile each regular expression only once, so that you can call match on the compiled patterns for efficiency. Lines are included in the output if for any of the read patterns, one line matches the pattern (produces a non-None result) and the other line doesn't (produces a None result) The body of my function was 7 lines (this number is not a requirement) For example if the iles pats1.txt, textsla.txt and texts1b.txt store the information shown below, calling multi compare (open ('patsl.txt', open ('textsla.txt'),open ('texts1b.txt') returns the following list [ (2, 'Iaaab', '666b6'), (3, 'ambulance7', '7a')] In pats1.txt, the first RE matches lines that start with an lower-case letter; the second RE matches lines that contain a b; the third RE matches lines that end in a digit. In the text files, lines 1 both match all three REs; the left line 2 matches only RE 2 while the right line 2 matches REs 2 and 3; the left line 3 matches all three REs while the right line 2 matches no REs; the lines 4 both match REs 2 and 3. textsla.txt ambulance7 !aaab ambulance7 4b17 texts1b.txt amoeba7 666b6 pats1.txt *ld* 666b6

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

Automating Access Databases With Macros

Authors: Fish Davis

1st Edition

1797816349, 978-1797816340

More Books

Students also viewed these Databases questions

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago