Created
April 19, 2016 16:39
-
-
Save mumbleskates/f09415f7102b41a3a020d87358f78266 to your computer and use it in GitHub Desktop.
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
# 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