Try itertools.permutations
:
from itertools import permutations
print('
'.join(map(''.join, list(permutations("abc", 3)))))
Output:
abc
acb
bac
bca
cab
cba
edit:
For an algorithm:
string = "abc"
def combinations(head, tail=''):
if len(head) == 0:
print(tail)
else:
for i in range(len(head)):
combinations(head[:i] + head[i+1:], tail + head[i])
combinations(string)
Output:
abc
acb
bac
bca
cab
cba
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…