Skip to content

Instantly share code, notes, and snippets.

@nikolak
Created August 7, 2016 21:07
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 nikolak/ea6a5692f046f62fcb2320aab1e62473 to your computer and use it in GitHub Desktop.
Save nikolak/ea6a5692f046f62fcb2320aab1e62473 to your computer and use it in GitHub Desktop.
def letter_count(s):
counter, max_index = 1, len(s) - 1
out = []
for index, letter in enumerate(s):
if index < max_index:
if letter == s[index + 1]:
counter += 1
continue
out.append("{}{}".format(counter, letter))
counter = 1
return "".join(out)
letter_count("aaaaabbbbccccccaaaaaaa") # '5a4b6c7a'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment