Problem 3 Define a class called Rle with a method Rle.__init__(self, values, lengths = None satisfying...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Problem 3 Define a class called Rle with a method Rle.__init__(self, values, lengths = None satisfying the following criteria: An Rle instance contains a run-length encoded object An Rle instance has list attributes called values and lengths If __init__() parameter lengths is None, then encode values using RLE Otherwise, initialize the attributes from the parameters Examples: In x = Rle (["hi", "hi", "hi", "lo", "lo", "hi", "lo", "lo", "10"]) In x.values Out: ['hi', 'lo', 'hi', 'lo'] In x.lengths Out: [3, 2, 1, 3] In y = Rle (["no", "yes", "no"], [3, 3, 11) In y.values Out: ['no', 'yes', 'no'] In y.lengths Out: [3, 3, 1] Problem 4 Define the method Rle. __getitem__(self, i) satisfying the following criteria: Returns the item at offset i of the decoded sequence . Should work for both positive and negative indices You do NOT need to implement slicing Examples: In: y = Rle (["no", "yes", "no"], [3, 3, 1]) In y [0] Out: 'no' In y [3] Out: 'yes' In y[-1] Out: 'no' Problem 5 Define the method Rle.append(self, value) satisfying the following criteria: Appends a new item value to the run-length encoded object Mutates the self instance and returns None Examples: In : y = Rle (["no", "yes", "no"], [3, 3, 11) In In y.values Out: ['no', 'yes', 'no', 'yes'] y.append("yes") In y.lengths Out: [3, 3, 1, 1] In y.append("yes") In y.values Out: ['no', 'yes', 'no', 'yes'] In y.lengths Out: [3, 3, 1, 2] 2 Problem 3 Define a class called Rle with a method Rle.__init__(self, values, lengths = None satisfying the following criteria: An Rle instance contains a run-length encoded object An Rle instance has list attributes called values and lengths If __init__() parameter lengths is None, then encode values using RLE Otherwise, initialize the attributes from the parameters Examples: In x = Rle (["hi", "hi", "hi", "lo", "lo", "hi", "lo", "lo", "10"]) In x.values Out: ['hi', 'lo', 'hi', 'lo'] In x.lengths Out: [3, 2, 1, 3] In y = Rle (["no", "yes", "no"], [3, 3, 11) In y.values Out: ['no', 'yes', 'no'] In y.lengths Out: [3, 3, 1] Problem 4 Define the method Rle. __getitem__(self, i) satisfying the following criteria: Returns the item at offset i of the decoded sequence . Should work for both positive and negative indices You do NOT need to implement slicing Examples: In: y = Rle (["no", "yes", "no"], [3, 3, 1]) In y [0] Out: 'no' In y [3] Out: 'yes' In y[-1] Out: 'no' Problem 5 Define the method Rle.append(self, value) satisfying the following criteria: Appends a new item value to the run-length encoded object Mutates the self instance and returns None Examples: In : y = Rle (["no", "yes", "no"], [3, 3, 11) In In y.values Out: ['no', 'yes', 'no', 'yes'] y.append("yes") In y.lengths Out: [3, 3, 1, 1] In y.append("yes") In y.values Out: ['no', 'yes', 'no', 'yes'] In y.lengths Out: [3, 3, 1, 2] 2
Expert Answer:
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Posted Date:
Students also viewed these programming questions
-
In a juice bottling process at the apple orchard plant located in Kentville, N.S., the actual amount poured by a filling machine into a 20-ounce bottle follows a normal distribution with a mean of...
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
QUIZ... Let D be a poset and let f : D D be a monotone function. (i) Give the definition of the least pre-fixed point, fix (f), of f. Show that fix (f) is a fixed point of f. [5 marks] (ii) Show that...
-
1. Find the probability of obtaining between 40 and 60 heads when tossing a coin 100 times. 2. Find the probability of obtaining 6s between 20 and 40 times when rolling a die 200 times.
-
If the U.N. follows through on a proposal to add production targets for 148 more items to its Sustainable Development Goals, why might we expect that the opportunity cost in terms of other goods and...
-
Evaluate the double integral by first identifying it as the volume of a solid. Sle (4 2y) dA, R= [0, 1] [0, 1]
-
Calculate backlog depreciation at 31 December 2005 for the plant and equipment, the details of which are given in Question 30.5A. Data From Question 30.5A:- The plant and equipment, details of which...
-
Provide an explanation in support of or refuting the following statement: Humans would never develop natural immunity to a novel biological agent created in a laboratory Explain how super-antigens,...
-
QUESTION 1 On September 25, Olive Oil Distributors receives an order from DeNarda Italian Supermarkets for 125 cases of extra virgin olive oil. Olive Oil accepts the order, which needs to be...
-
In spring 2021, Amir Nathoo was at the helm of one of the most talked-about startups in the massive and fragmented educational technology (EdTech) industry. Just six years earlier, Nathoo and his...
-
Calculate SL dzdy where D is the region bouded by y=r3 and line y=r.
-
Describe in one sentence what Ricardian equivalence implies for the government budget and the current account. In another sentence, describe to what extent the equivalence holds in practice. In the...
-
How the development of China and rise of BRICS may contribute to the new "world order"? What is the outlook for the US economy given the future presidential candidates and the current presidential...
-
In this board you are to address the build-up of intelligence collection operations against suspected Taliban and AQ targets in the area around Gardez and Khost, Afghanistan. The object is to allow...
-
Many years ago, many politicians argued that because Microsoft Windows was installed on 90% of personal computers worldwide, it had a monopoly on the PC Operating Systems market. Does that argument...
-
Consider the indefinite integral, 7(x): 1(x) = = x+4x= x+4x-17 -dx = F(x)+c x-3 where F(x) is the primitive and c is the integration constant. If1(k) =0 where k = 4.6, find the value of c. Give your...
-
Page < Write a narrative of your process of answering the above question. Be specific. Include sources and links. For example, if your first thought is to ask your sister, who is busy taking AP...
-
Keating & Partners is a law firm specializing in labour relations and employee-related work. It employs 25 professionals (5 partners and 20 managers) who work directly with its clients. The average...
-
In Exercises 23.2023.21, you reimplemented recursive sorting algorithms using the Fork/Join Framework. Why might you not want to invest the effort into applying this technique to a recursive binary...
-
Write an application that displays the numbers 1 to 4 on the same line, with each pair of adjacent numbers separated by one space. Use the following techniques: a) Use one System.out.println...
-
Overload generic method printArray of Fig. 20.3 with a nongeneric version that specifically prints an array of Strings in neat, tabular format, as shown in the sample output that follows: Fig. 20.3...
-
Will a company with ample growth opportunities tend to issue short-term, mediumterm or long-term debt? Why?
-
If you believe a finance directors main concern is financial flexibility, would you expect a company ever to use up its borrowing capacity?
-
Which is the fundamental journal article on the subject of capital structure?
Study smarter with the SolutionInn App