计算给定字符串的排列-'NoneType'对象不可迭代

时间:2019-05-25 21:42:31

标签: python

我的代码适用于长度为2的列表,但对于其他任何操作,我都无法获得'NoneType'对象。我是python的新手,并且刚刚完成了崩溃课程,因此将不胜感激。

def permutation(list1):
    if len(list1) == 0:
        print("There are no permuations.")

    elif len(list1) == 1:
        return[list1]

    else:
        for i in range(len(list1)):
            newlist = list1[1:]
            for perm in permutation(newlist):
                perm.insert(i,list1[0])
            print(perm)

因此对于[a,b]的列表,我得到[a,b],[b,a]。 但是当我尝试[a,b,c]时,我收到nonetype错误,并且不确定为什么。

0 个答案:

没有答案