Question
Challenge not required and please read the problem carefully. USE PYTHON3, DO NOT IMPORT ANY PACKAGES!! The Mentioned Outfiles plus their copied text for your
Challenge not required and please read the problem carefully. USE PYTHON3, DO NOT IMPORT ANY PACKAGES!!
The Mentioned Outfiles plus their copied text for your convenience:
**Marina** MarinaMarinaMarinaMarinaMarina ******MarinaMarinaMarinaMarinaMarinaMarina******
__________________________________________________________________________________________________________________
____()()()()____ __()()____()()__ ()()________()() ()____________()
_____________________________________________________________________________________
####______####____####__####______##__ ##__##__##______##__________##__##__## ##__##____##____##________##____##__## ##__##______##__##______##______##__## ####____####______####__######____##__
Arda is an artist that loves to draw random patterns with ASCII characters in Notepad. One day, he noticed that his drawings have too many repeated characters, such that his hard drive cannot fit his portfolio. He decided to write a serialization algorithm to compress the file size. He found that each line of his drawings happens to be repeating some sub-patterns in certain order. Thus, he serializes the drawings to a list of all sub-patterns that occurred and the counts of consecutive occurrences in each line. Example: Suppose the line is "OOOOAAABBOBBBBB", and patterns list is ["AAA", "B", "O"), the serialization algorithm will first look for the first pattern in patterns list ("AAA"), count until it meets a different pattern, and start look for the second pattern ("B"), etc. When the patterns list is exhausted, the algorithm wraps back to the first pattern. Thus, the count list for this line is generated like follows: "OOOOAAABBOBBBBB" -> [("AAA", O), ("B", 0), ("0", 4), ("AAA", 1), ("B", 2), ("O", 1), ("AAA", O), ("B", 5)] -> [0, 0, 4, 1, 2, 1, 0, 5] Explanation: You start with the first pattern from the list: "AAA" and the first character in the string: "0". There is no match, therefore the tuple is ("AAA", 0) You continue with the second pattern from the list: "B" and still the first character in the string: "O". There is not match, so the tuple is ("B", 0)) You continue with the third pattern: "0" and again, the first character in the string: "O". This time there is a match, you count it as one match and move one to the next character in the string. Repeat this 4 times and get the tuple: ("O", 4). Move one more time and see a mismatch. Then you start over with the pattern list and try "AAA" again. You have your first match by one character and therefore can move along the pattern and the string to get ("AAA", 1) Repeat the steps until you are done with the string. After serialization, he needs a deserialization algorithm that converts the serialized lists back to a drawing file. The patterns argument is a list of all sub-patterns (with arbitrary length). The serialized_lines position arguments are lists of counts, where each list represents one line. Convert lines back to the original string, and write it to a file (with outpath as path). Notes: (1) We have provided three files (outfiles/out{1,2,3}.txt), which are the output after running the provided doctest against our solution. Note that if you run doctests for this question before implementing it, the tests might pass since our provided files are correct. (2) Avoid using >' (greater than),'' (dot)," (space) and quotation marks in your doctest cases, since they might conflict with the reserved characters in doctests. (3) Due to some flaws in Arda's serialization algorithm, the count lists might contain some unnecessary Os (such as the (3,3,0,3,3] in doctest 1, which can be further compressed as [3,6,3]). They will not affect the deserialized string. (4) Due to more flaws in Arda's serialization algorithm, you may find some sub-patterns in the patterns list are not present in the actual string. They won't affect the result since all nonexistent sub-patterns have count 0. Challenge (not required): Construct the deserialized string with one-line list comprehension. The built-in function str.join() will be helpful to concatenate a list of strings. Example: deserialize(Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started