Python: Create a list reflecting the run-length encoding from a list
Create Run-Length Encoded List
Run-length encoding (RLE) is a form of lossless data compression in which runs of data (sequences in which the same data value occurs in many consecutive data elements) are stored as a single data value and count, rather than as the original run.
Write a Python program to create a list reflecting the run-length encoding from a given list of integers or a given list of characters.
Sample Solution:
Python Code:
Sample Output:
Original list: [1, 1, 2, 3, 4, 4.3, 5, 1] List reflecting the run-length encoding from the said list: [[2, 1], [1, 2], [1, 3], [1, 4], [1, 4.3], [1, 5], [1, 1]] Original String: automatically List reflecting the run-length encoding from the said string: [[1, 'a'], [1, 'u'], [1, 't'], [1, 'o'], [1, 'm'], [1, 'a'], [1, 't'], [1, 'i'], [1, 'c'], [1, 'a'], [2, 'l'], [1, 'y']]
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Python program to implement run-length encoding for a string.
- Write a Python program to decode a run-length encoded list back to the original list.
- Write a Python program to perform run-length encoding, but group elements into tuples.
- Write a Python program to find the most frequently occurring element using run-length encoding.
Go to:
Previous: Write a Python program to pack consecutive duplicates of a given list elements into sublists.
Next: Write a Python program to create a list reflecting the modified run-length encoding from a given list of integers or a given list of characters.
Python Code Editor:
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.