Text processing · 12 / 14 Exercise Medium

Text compression

Objective

Create a Python program that compresses a text by indicating how many times each letter is repeated consecutively.

Instructions

  • Read a non-empty text without spaces.
  • Go through the text grouping the equal characters that come one after another.
  • Show each character followed by the number of times it is repeated, even if it is only once. For example, aaabcc becomes a3b1c2.
  • The groups are not merged: aabbaa becomes a2b2a2.
Input
aaabcc
Output
a3b1c2

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise