def data_check(head):
data = [1, 2, 1]
n_head = len(head)
n_data = len(data)
n = n_head if n_head < n_data else n_data
if head[:n] == data[:n]:
return True
else:
return False
def perm(head, rest):
if not data_check(head):
return None
if len(rest) == 0:
return [head]
else:
result = []
data = sorted(set(rest))
for i in data:
print(head)
rest_del = rest[:]
rest_del.remove(i)
head_add = head + [i]
temp = perm(head_add, rest_del)
if temp:
result += temp
return result
junretsu = perm([], [1, 1, 1, 2, 2, 3])
print(len(junretsu))
print(junretsu)