Skip to content

Instantly share code, notes, and snippets.

@viniceosm
Created January 10, 2020 12:34
Show Gist options
  • Save viniceosm/865477f4edea7731433dc26dafc97a51 to your computer and use it in GitHub Desktop.
Save viniceosm/865477f4edea7731433dc26dafc97a51 to your computer and use it in GitHub Desktop.
permute
def permute(xs, low=0):
if low + 1 >= len(xs):
yield xs
else:
for p in permute(xs, low + 1):
yield p
for i in range(low + 1, len(xs)):
xs[low], xs[i] = xs[i], xs[low]
for p in permute(xs, low + 1):
yield p
xs[low], xs[i] = xs[i], xs[low]
for p in permute(["vini", "TESTE"]):
print ''.join(p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment