def permutation(list: [], left: int, right: int):
if left == right:
print(list);
else:
for i in range(left, right + 1):
list[left], list[i] = list[i], list[left]
permutation(list, left + 1, right)
list[left], list[i] = list[i], list[left]
def permutation2(list: [], size: int, n: int):
if size == 1:
print(list)
for i in range(0, size):
permutation2(list, size - 1, n)
# if size % 2 == 1:
# list[0], list[size - 1] = list[size - 1], list[0]
# else:
# list[i], list[size - 1] = list[size - 1], list[i]
if i != size - 1:
list[i], list[size - 1] = list[size - 1], list[i]
elif i >= 1:
list[i - 1], list[size - 1] = list[size - 1], list[i - 1]
if __name__ == '__main__':
permutation(['a', 'b', 'c'], 0, 2)
permutation2(['a', 'b', 'c'], 3, 3)