#!/usr/bin/env python
 
def perm(n, i):
	if i == len(n) - 1:
		print(n)
	else:
		for j in range(i, len(n)):
			n[i], n[j] = n[j], n[i]
			perm(n, i + 1)
			n[i], n[j] = n[j], n[i] # swap back, for the next loop


perm([1,2,3],0) 
perm(['c','a','t','d','o','g'],0)
																							         
