Filename: runlength_decoder.py Starter code for data: hw4data.py Download hw4data.py  Download hw4data.pyYou must provide a function named decode() that takes a list of RLE-encoded values as its single parameter, and returns a list containing the decoded values with the “runs” expanded. If we were to use Python annotations, the function signature would look similar to this: def decode(data : list) -> list: Run-length encoding (RLE) is a simple, “lossless” compression scheme in which “runs” of data. The same value in consecutive data elements are stored as a single occurrence of the data value, and a count of occurrences for the run. For example, using Python lists, the initial list:     [‘P’,‘P’,‘P’,‘P’,‘P’,‘Y’,‘Y’,‘Y’,‘P’,‘G’,‘G’] would be encoded as:     ['P', 5, 'Y', 3, ‘P’, 1, ‘G’, 2] So, instead of using 11 “units” of space (if we consider the space for a character/int 1 unit), we only use 8 “units”.  In this small example, we don’t achieve much of a savings (and indeed the smaller your overall data size, the less opportunity for any compression algorithm to save much space) but imagine if we had a run of 30 or 40 P’s and 10 Y’s. The space savings begin to add up. Our RLE scheme for this assignment uses the format shown in the example above. Data is contained in a list such that the elements follow the pattern:   Notice the data contained in our list is heterogeneous. In other words, it's NOT all the same type. strings and integers are interleaved in the list. Be sure to consider this as you're designing your solution. Do this: Write a program that decompresses the data included in the file starter file hw4data.py. IMPORTANT: Import hw4data.py, do NOT copy/paste the data! If you copy-paste and introduce a subtle data error due to "fat fingering" or some other mistake, your RLE program may not work correctly and you will lose points. The data is a Python file - import it as any other "outside asset" file (e.g. external functions) and proceed from there. There are six data values of increasing size and complexity: DATA0, DATA1, …DATA5. Your program must provide a function named decode(list) that takes a list of RLE-encoded values and returns a list containing the decoded values with the “runs” expanded. We will call your decode() function in our test suite, so name the function exactly as specified, and make sure it returns a Python list. Optional: We're using some fun compressed data, but it's all textual. If you want to actually see the original information, you can convert the decompressed (decoded) list into one single string value, then display that string on the screen using the print() statement.  Again, this step is optional and for your personal enjoyment to view the data. Given the example data discussed above, the screen output would be something like this:   Notes  WE do not want to see your decoded data printed out. IF you perform this optional step be sure to keep this separate from the core functionality you're submitting for your assignment. WARNING: Do NOT use your decode() function for optional actions described above. You are free to create other helper functions to convert and display the decompressed data.  You will lose points if your decode() function does more than the specified decompression algorithm.   You can assume “good” data and it conforms to the RLE scheme described without any missing elements.       What to submit: Your solution in a file named: runlength_decoder.py, which contains the function decode() as specified above. You may include other files with any “helper” functions you’ve written. Documentation/comments in runlength_decoder.py should indicate any additional helper files you’ve included

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
    • Filename: runlength_decoder.py
    • Starter code for data: hw4data.py Download hw4data.py 
    • Download hw4data.pyYou must provide a function named decode() that takes a list of RLE-encoded values as its single parameter, and returns a list containing the decoded values with the “runs” expanded. If we were to use Python annotations, the function signature would look similar to this:
      def decode(data : list) -> list:

    Run-length encoding (RLE) is a simple, “lossless” compression scheme in which “runs” of data. The same value in consecutive data elements are stored as a single occurrence of the data value, and a count of occurrences for the run.

    For example, using Python lists, the initial list:

        [‘P’,‘P’,‘P’,‘P’,‘P’,‘Y’,‘Y’,‘Y’,‘P’,‘G’,‘G’]

    would be encoded as:

        ['P', 5, 'Y', 3, ‘P’, 1, ‘G’, 2]

    So, instead of using 11 “units” of space (if we consider the space for a character/int 1 unit), we only use 8 “units”.  In this small example, we don’t achieve much of a savings (and indeed the smaller your overall data size, the less opportunity for any compression algorithm to save much space) but imagine if we had a run of 30 or 40 P’s and 10 Y’s. The space savings begin to add up.

    Our RLE scheme for this assignment uses the format shown in the example above. Data is contained in a list such that the elements follow the pattern:

     

    Notice the data contained in our list is heterogeneous. In other words, it's NOT all the same type. strings and integers are interleaved in the list. Be sure to consider this as you're designing your solution.

    Do this:

    • Write a program that decompresses the data included in the file starter file hw4data.py.
      IMPORTANT: Import hw4data.py, do NOT copy/paste the data! If you copy-paste and introduce a subtle data error due to "fat fingering" or some other mistake, your RLE program may not work correctly and you will lose points. The data is a Python file - import it as any other "outside asset" file (e.g. external functions) and proceed from there.
    • There are six data values of increasing size and complexity: DATA0, DATA1, …DATA5. Your program must provide a function named decode(list) that takes a list of RLE-encoded values and returns a list containing the decoded values with the “runs” expanded. We will call your decode() function in our test suite, so name the function exactly as specified, and make sure it returns a Python list.

    Optional:
    We're using some fun compressed data, but it's all textual. If you want to actually see the original information, you can convert the decompressed (decoded) list into one single string value, then display that string on the screen using the print() statement.  Again, this step is optional and for your personal enjoyment to view the data. Given the example data discussed above, the screen output would be something like this:

     



    Notes
     

    • WE do not want to see your decoded data printed out. IF you perform this optional step be sure to keep this separate from the core functionality you're submitting for your assignment.
      WARNING: Do NOT use your decode() function for optional actions described above. You are free to create other helper functions to convert and display the decompressed data.  You will lose points if your decode() function does more than the specified decompression algorithm.

       

    • You can assume “good” data and it conforms to the RLE scheme described without any missing elements.

 

    What to submit:

    • Your solution in a file named: runlength_decoder.py, which contains the function decode() as specified above.
    • You may include other files with any “helper” functions you’ve written. Documentation/comments in runlength_decoder.py should indicate any additional helper files you’ve included
[ 'P', 5, 'Y', 3,...]
↑
X
value
occurrence
in run
Transcribed Image Text:[ 'P', 5, 'Y', 3,...] ↑ X value occurrence in run
= RESTART: /Users/keithbagley/Dropt
mework/HW4/runlength_decoder.py
Decoding run-length encoded data
PPPPPYYYPGG
Transcribed Image Text:= RESTART: /Users/keithbagley/Dropt mework/HW4/runlength_decoder.py Decoding run-length encoded data PPPPPYYYPGG
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Stack operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education