Created
May 7, 2018 12:22
-
-
Save StanDimitroff/fc78d77b1bc4c3d754fb26b0ee6c3d8a to your computer and use it in GitHub Desktop.
Run-length decoding implementation in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def decode(text): | |
""" | |
Decodes the text using run-length encoding | |
""" | |
return re.sub(r'(\D)(\d*)', lambda m: m.group(1) * int(m.group(2)) if m.group(2) != '' else m.group(1), text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment