Skip to content

Instantly share code, notes, and snippets.

@johnpena
Created February 8, 2011 19:58
Show Gist options
  • Save johnpena/817083 to your computer and use it in GitHub Desktop.
Save johnpena/817083 to your computer and use it in GitHub Desktop.
Get all of a string's substrings
def get_all_substrings(string):
substrings = []
for i in xrange(len(string)):
n = i
while n >= 0:
substrings.append(string[n:i+1])
n -= 1
return substrings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment