Answer:
We have the following code in python with appropriate comments
Step-by-step explanation:
line = input("Enter your line of integers: ")
# Splits at space
intList = line.split()
#initializing the count to 1
count = 1
#initializing the count to empty string
output = ''
#iterating over the list
for index, x in enumerate(intList):
#handling last index separately
if index == len(intList)-1:
if intList[index] == intList[index-1]:
output = output + str(count) + ' ' + str(intList[index])
else:
count = 1
output = output + str(count) + ' ' + str(intList[index])
#handling indexes other than the last index
else:
if intList[index]==intList[index+1]:
count = count + 1 #if next integer is same, we increase the count by 1
else:
output = output + str(count) + ' ' + str(intList[index]) + ' '
count = 1
print(output)