Created
August 7, 2016 21:07
-
-
Save nikolak/ea6a5692f046f62fcb2320aab1e62473 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
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