Skip to content

Instantly share code, notes, and snippets.

@corehello
Created January 11, 2021 15:28
Show Gist options
  • Save corehello/94bc2766ac60b984782132ae60944f66 to your computer and use it in GitHub Desktop.
Save corehello/94bc2766ac60b984782132ae60944f66 to your computer and use it in GitHub Desktop.
string permutation
def perm(string):
if len(string) <= 1:
return [string]
return [i+j for idx,i in enumerate(string)
for j in perm(string[0:idx] + string[idx+1:])]
if __name__ == "__main__":
TCs = [
("a", ["a"]),
("ao", ["ao", "oa"])
]
for TC in TCs:
if perm(TC[0]) == TC[1]:
print("SUCCEED TC: %s" % TC[0])
else:
print("FAILED TC: %s" % TC[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment