Skip to content

Instantly share code, notes, and snippets.

@mumbleskates
Created April 19, 2016 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mumbleskates/f09415f7102b41a3a020d87358f78266 to your computer and use it in GitHub Desktop.
Save mumbleskates/f09415f7102b41a3a020d87358f78266 to your computer and use it in GitHub Desktop.
# coding=utf-8
import re
def simple_compress(s):
c = ''.join((part[1] + (str(len(part[0])) if len(part[0]) > 1 else '')) for part in re.findall(r'((.)\2*)', s))
return c if len(c) < len(s) else s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment