I have a Python list with a variable number of elements.

[a,b,c,d,e]

I need to rearrange these elements inside the list and find all possible unique combinations.

[a,b,c,d,e]
[d,b,a,e,c]
[e,d,a,c,b], etc.

I cannot have same elements repeated, or have any elements removed:

[a,a,a,d,e]  <-- bad
1  
OK. Now, what have you tried to solve this, and can you show your code and explain what difficulties you are facing in your implementation? – idjaw 4 hours ago

2 Answers 2

You should use itertools.permutations, for example:

import itertools
my_list = [a, b, c, d]
for x in itertools.permutations(my_list):
    print(x)

You want itertools.permutations([a,b,c,d,e]).