Created
November 29, 2016 12:30
-
-
Save LeonardoCardoso/27da2545550901b18ba3bcc690d78b4a to your computer and use it in GitHub Desktop.
Generate all combinations of a string, uppercase and lowercase.
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 recurse (pref,suff): | |
# If no characters left, just print prefix. | |
if suff == "": | |
print pref | |
return | |
# Otherwise add lowercase of first suffix letter to prefix | |
# and recur with that and the remainder of the suffix. | |
# Then do the same for uppercase. | |
# If you wanted smarts, this is where you'd detect if the | |
# upper and lower were the same and only recurse once. | |
recurse (pref + suff[0:1].lower(), suff[1:]) | |
recurse (pref + suff[0:1].upper(), suff[1:]) | |
# Test the function with "macOS". | |
recurse ("","macos") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment