编程语言
首页 > 编程语言> > 递归实现全排列python

递归实现全排列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")

标签:abcd,head,排列,string,递归,python,father,不动,pailie
来源: https://www.cnblogs.com/double-t/p/11143256.html