Created
August 5, 2016 19:44
-
-
Save brizandrew/c4643d3d535f872f314c5161c68fc8e7 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
""" | |
@function indexOfAll | |
Utility function to find the index of every instance of a given substring in a string | |
@param {str} string: The string to search through | |
@param {str} sub: The substring to search for | |
@return {int[]}: A list of indeces everywhere that substring appears | |
""" | |
def indexOfAll(string, sub): | |
output = [] | |
for i in range(0,len(string)): | |
try: | |
if string[i:i+len(sub)] == sub: | |
output.append(i) | |
except IndexError: | |
pass | |
return output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment