Last active
December 29, 2016 05:45
-
-
Save drem-darios/293fa9cf2e4ce5ea02cd2c97d12e3116 to your computer and use it in GitHub Desktop.
Example of how to print all permutations of a 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 permutation(str): | |
_permutation('', str) | |
def _permutation(prefix, str): | |
n = len(str) | |
if n == 0: | |
print prefix | |
else: | |
for i in range(0, n): | |
_permutation(prefix + str[i], str[0:i] + str[i + 1:n]) | |
def main(): | |
permutation('abc') | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment