Created
August 9, 2016 15:08
-
-
Save jehugaleahsa/75998ae61ad0df86d11fa23fa4c77593 to your computer and use it in GitHub Desktop.
Python - Count Occurrences
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 getSegments(input): | |
start = 0 | |
length = len(input) | |
while start != length: | |
current = input[start] | |
end = next((i for i in range(start, length) if input[i] != current), length) | |
count = end - start | |
yield (count, current) | |
start = end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment