permutating on list
Question: > **Possible Duplicate:**  
>  [How to generate all permutations of a list in
> Python](http://stackoverflow.com/questions/104420/how-to-generate-all-
> permutations-of-a-list-in-python)

I'm writing a function, called permutate(lst, acc) that permutes on the list
of integers, finding its all possible permutation. For example,
permutate([1,2,3],[0]) should return [123,132,213,231,312,321], but not
necesarily in that order. acc is an accumulator, that is carried on through
the recursion. What I have so far, is

    
    
    def permutate(lst, acc):
        if not lst:
            return acc
        else:
            return reduce(lambda x, y: x + y, 
            map(lambda z: permutate(lst[:].remove(z), 
            map(lambda a: a * 10 + z, acc[:])), lst[:]))
    

currently permutate([1,3,2,5],[0]) returns [1,3,2,5]. I'm guessing the
function is not making its recursive steps. I also avoided list being mutable,
by adding [:]. any thoughts?


Answer: Use the Python library itertools:

    
    
    from itertools import permutations
    permutations([1,2,3])
    

It's included with Python, so you won't have to install anything.

