98. Problem to decode a run-length encoded list.

In this Python list program, we will take a run-length encoded list as input and decode it in a list with the help of the below-given steps.

Decode run-length encoded list:

Steps to solve the program
  1. Take a run-length encoded list as input and create an empty list.
  2. Use for loop to iterate over every element from the list.
  3. If an element is encoded list then replace the first element of the list with the second element and add it to the empty list.
  4. Print the list to see the output.
				
					#Input list
list1 = [[2, 1], 2, 3, [2, 4], 5, 1]
list2 = []

for value in list1:
    if isinstance(value,list):
        value[0] = value[1]
        list2.append(value[0])
        list2.append(value[1])
    else:
        list2.append(value)

#Printing output
print(list2)
				
			

Output :

				
					[1, 1, 2, 3, 4, 4, 5, 1]
				
			

Related Articles

Python program to round every number in a given list of numbers and print the total sum of the list.

Python Program to get the Median of all the elements from the list.

Python Program to get the Standard deviation of the list element.

Python program to convert all numbers to binary format from a given list.

Python program to convert all the numbers into Roman numbers from the given list.

Python program to calculate the square of each number from the given list.

 

 

 

Remove duplicate dictionaries from the list

Round every number in a given list of numbers

Leave a Comment