Skip to content

Instantly share code, notes, and snippets.

@ilyannn
Last active August 29, 2019 15:28
Show Gist options
  • Save ilyannn/ce9928b0b2b357d0fb831591e35ee16d to your computer and use it in GitHub Desktop.
Save ilyannn/ce9928b0b2b357d0fb831591e35ee16d to your computer and use it in GitHub Desktop.
Almost one-liner fold
def fold(s, p = 0):
for i in [i+1 for (i, c), n in zip(enumerate(s), s[1:]+' ') if c != n]: p = print(s[p], i-p, sep="", end="") or i
@ilyannn
Copy link
Author

ilyannn commented Aug 29, 2019

> fold('aaabbbbcca')
a3b4c2a1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment