【问题标题】:TypeError 'int'类型错误'int'
【发布时间】:2015-07-31 15:16:32
【问题描述】:

我正在尝试使一个函数返回一个数字列表的所有可能排列,例如: 列表= [1,2,3]

[[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2],[3,2,1 ]]

但是我一直遇到同样的错误 TypeError:“int”对象不可调用 在这一行

return permutations(result,variable,List,permutations)

剩下的代码是

def permutationsaux(List):
    if List==[]:
        return []
else:
    return permutations([List],0,List,countpermutations(List))

def permutations(result,variable,List,permutations):
    if len(result)==permutations:
        return result
    elif len(result[variable])==len(List):
        result.append([])
        variable=variable+1
        return permutations(result,variable,List,permutations)
    return permutations(result[variable]+reorderlist(List),variable+1,reorderlist(lista),permutations)

def countpermutations(List):
    if List==[]:
        return 1
    return len(List)*countpermutations(List[1:])

def reorderlist(List):
    temp=List[len(List)-2]
    List[len(List)-2]=LIst[len(List)-1]
    List[len(List)-1]=temp
    return List

【问题讨论】:

    标签: python-3.x recursion typeerror


    【解决方案1】:

    您的函数“permutations”有一个名为“permutations”的参数。猜猜哪个在函数范围内。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-20
      • 2022-09-27
      • 2023-03-25
      • 1970-01-01
      相关资源
      最近更新 更多