Skip to content

Instantly share code, notes, and snippets.

@a-agmon
Last active April 2, 2022 17:38
Show Gist options
  • Save a-agmon/93953e8bc2085abd42e85f804dc3d075 to your computer and use it in GitHub Desktop.
Save a-agmon/93953e8bc2085abd42e85f804dc3d075 to your computer and use it in GitHub Desktop.
def perm(orig_str, new_str=""):
if(len(new_str) == len(orig_str)):
print(new_str)
else:
for char in orig_str:
if(char not in new_str):
perm(orig_str, new_str + char)
# another version
def perm(orig_str, new_str=""):
if(len(orig_str) == 0):
print(new_str)
else:
for char in orig_str:
perm(orig_str.replace(char,""), new_str + char)
perm("ABC")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment