Skip to content

Instantly share code, notes, and snippets.

@suminb
Created September 3, 2013 21:41
Show Gist options
  • Save suminb/6429982 to your computer and use it in GitHub Desktop.
Save suminb/6429982 to your computer and use it in GitHub Desktop.
Compute all non-empty substrings of a given string
def substrings(s):
n = len(s)
for i in xrange(0, n):
for j in xrange(i+1, n+1):
yield s[i:j]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment