递归实现全排列python

python递归实现"abcd"字符串全排列

1.保持a不动,动bcd
2.保持b不动,动cd
3.保持c不动,动d

def pailie(head="",string=""):
    if len(string)>1:
        for father_string in string:
            pailie(head+father_string,string.replace(father_string,"")) #关键一点:将头和尾全部传下去
    else:
        print(head+string)


pailie(string="abcd")
上一篇:Python3之用内建模块base64


下一篇:2019高考,李尚志教授三评“维纳斯”(来自网络)