Anagram

Find all permutations of a string
import sys from math import factorial s = sys.argv[1] from math import factorial def perm(s): for i in range(factorial(len(s))): print( '' .join(s)) p=len(s)-1 while (p > 0) and (s[p-1] > s[p]): p=p-1 s[p:] = reversed(s[p:]) if p > 0: q = p             while s[p-1] > s[q]: q=q+1 s[p-1],s[q]=s[q],s[p-1] s = list(s) s.sort perm(s)
 * 1) !/usr/bin/python