Slightly different version, Arnau Sanchez, 2007/08/05
def permutations(lst):
remove = lambda lst0, index: lst0[:index] + lst0[index+1:]
if lst:
for index, x in enumerate(lst):
for y in permutations(remove(lst, index)):
yield (x,)+y
else: yield ()
Although it does not work the same way with strings.
Add comment