Created
September 3, 2013 21:41
-
-
Save suminb/6429982 to your computer and use it in GitHub Desktop.
Compute all non-empty substrings of a given string
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 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