Created
October 1, 2011 17:57
-
-
Save fjorgemota/1256415 to your computer and use it in GitHub Desktop.
Iterator Python que permite dar split em uma String progressivamente conforme o decorrer de um Loop
This file contains hidden or 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 SplitIterator(s,separator): | |
| s = list(s) | |
| c = 0 | |
| l = len(separator) | |
| separator = list(separator) | |
| last_token = [] | |
| while s[c:]: | |
| if s[c:c+l] == separator: | |
| a = "".join(last_token) | |
| last_token = [] | |
| yield a | |
| else: | |
| last_token.extend(s[c]) | |
| c += 1 | |
| yield "".join(last_token) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment