I would take this in a different direction and suggest you not use a global
to store your recursive function's results, but rather bubble the results back up through the recursion itself:
def zir_maj(array):
permutations = []
if array:
head, *tail = array
sub_permutations = zir_maj(tail)
for sub_permutation in sub_permutations:
permutations.append([head, *sub_permutation])
permutations.extend(sub_permutations)
permutations.append([head])
return permutations
print(zir_maj(['a', 'b', 'c']))
OUTPUT
% python3 test.py
[['a', 'b', 'c'], ['a', 'c'], ['a', 'b'], ['b', 'c'], ['c'], ['b'], ['a']]
%
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…