What is an elegant way to find all the permutations of a string. E.g. permutation for ba, would be ba and ab, but what about longer st
ba
ab
python implementation
def getPermutation(s, prefix=''): if len(s) == 0: print prefix for i in range(len(s)): getPermutation(s[0:i]+s[i+1:len(s)],prefix+s[i] ) getPermutation('abcd','')