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


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

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

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

[a,a,a,d,e]  <-- bad
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):

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