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
-
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.
-
Why might a person pay a firm at a mall to prepare her tax forms while she shops instead of allocating the same amount of time to finding a qualifying Free-File tax preparation service? What must be...
-
List the deliverables from the conceptual data modeling part of the analysis phase of the systems development process.
-
Determine the maximum axial force P that can be applied to the bar. The allowable stress is allow = 21 ksi. P 1.875 in. 0.125 in. 1.25 in. 0.75 in. r = 0.25 in. P
-
In the following example, assume that the only court opinion on point is United States v. Leon (see Appendix A). Facts: Officer Jones submits to Judge Bean a request for a search warrant for the...
-
How can chemical engineering principles be applied to optimize the production of biofuels from lignocellulosic biomass? Consider the various pretreatment methods, enzymatic hydrolysis, and...
-
1. Navigate to the threaded discussion below and respond to the following: A. Why is the ability to conduct effective and productive meetings important for a supervisor? B. What factors should a...
-
Discussion: Are Facebook friends the same as real friends? Are Facebook fans real fans? Explain.
-
What is social media marketing? What marketing objectives can organizations meet when they incorporate social media in their marketing mix?
-
How does information flow in a network?
-
A statement of financial position is to be drawn up from the following information as at 30 September 2011: Issued share capital: ordinary shares 1 each Authorised share capital: ordinary shares of 1...
-
Draw up a statement of cash flows for Gerry Peace for the year ending 31 December 2013 using the IAS 7 layout. You are told that fixtures bought in 2003 cost 400, whilst a van was bought for 5,500....
-
How can grocery receipts be generated from a database system?
-
Danielle has an insurance policy with a premium of $75 per month. In September she is in an accident and receives a bill worth $2990 for the repair of her own property. Her deductible is $250 and her...
-
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...
-
The swinging spring is an example of a two degree-of-freedom system with a cubic nonlinearity. Indicate whether the statement presented is true or false. If true, state why. If false, rewrite the...
-
The period of free vibrations of a nonlinear system depends upon initial conditions. Indicate whether the statement presented is true or false. If true, state why. If false, rewrite the statement to...
-
A mass attached to a linear spring sliding on a surface with Coulomb damping is an example of a nonlinear system. Indicate whether the statement presented is true or false. If true, state why. If...
Study smarter with the SolutionInn App