Skip to content

Instantly share code, notes, and snippets.

@StanDimitroff
Created May 7, 2018 12:22
Show Gist options
  • Save StanDimitroff/fc78d77b1bc4c3d754fb26b0ee6c3d8a to your computer and use it in GitHub Desktop.
Save StanDimitroff/fc78d77b1bc4c3d754fb26b0ee6c3d8a to your computer and use it in GitHub Desktop.
Run-length decoding implementation in python
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