I have a list:
s=[[[’A’, ’B’], [’C’]],[[’A’], [’B’]], [[’B’], [’A’]]]
The length of this list is 3, which means I should get 6 different order of this list:
which means the result should be
[[[’A’, ’B’], [’C’]],[[’A’], [’B’]], [[’B’], [’A’]]]
[[[’A’], [’B’]],[[’A’, ’B’], [’C’]], [[’B’], [’A’]]]
[[[’B’], [’A’]],[[’A’], [’B’]],[[’A’, ’B’], [’C’]]]
.....
My code is:
COUNT=0
order = []
def perm(n,begin,end):
global COUNT
if begin>=end:
order.append(n)
COUNT +=1
else:
i=begin
for num in range(begin,end):
n[num],n[i]=n[i],n[num]
perm(n,begin+1,end)
n[num],n[i]=n[i],n[num]
return order
F = [[['A', 'B'], ['C']],[['A'], ['B']], [['B'], ['A']]]
perm(F,0,len(F))
But this result is wrong, it returns six times the same list!