Question: Given n positive integers over multiple lines, where n is provided in the first line, print the run - length encoding sequence for each number

Given n positive integers over multiple lines, where n is provided in the first line, print the run-length encoding sequence for each number on separate lines. Run-length encoding represents how many times a digit is repeated consecutively.
For each number, every two values in the output represent the count of consecutive digits followed by the digit itself.
Input
The first line contains an integer n representing the number of integers.
The next n lines each contain one integer.
Output
For each of the n integers, print the run-length encoded sequence on a new line. Each line contains pairs of numbers where the first number in each pair is the count of consecutive digits, followed by the digit itself.
Example
For example, given the following input:
4
44455544445
666666
77778888877
234567
The output should be:
343544415
66
475827
121314151617
Explanation
44455544445-34354415-3 times 4,3 times 5,4 times 4 and 1 time 5
666666-66-6 times 6
77778888877-475827-4 times 7,5 times 8,2 times 7
234567-121314151617-1 time 2,1 time 3,1 time 4,1 time 5,1 time 6,1 time 7
The below code is written by me, i am getting the correct output but i am not able to print it in correct format
Test Case 1
# Write your code here
# Take the input from standard input using input()
# and print the output according to the problem .
# Write your code here
n=int(input())
integer_list=[]
for i in range(n):
integer_list.append(str(input()))
count=0
current_char=''
for j in range(len(integer_list)):
for k in str(integer_list[j]):
if(k!=current_char):
if(current_char!=''):
print(count+1,current_char,end='')
count=0
current_char=k
else:
current_char=k
else:
count+=1
Given n positive integers over multiple lines,

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!