Skip to content
Advertisement

Create a compress function in Python?

I need to create a function called compress that compresses a string by replacing any repeated letters with a letter and number. My function should return the shortened version of the string. I’ve been able to count the first character but not any others.

Ex:

JavaScript

Advertisement

Answer

Here is a short python implementation of a compression function:

JavaScript

Here are a few examples:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement