[Python] What's wrong with this recursive code for permutations? [duplicate]

Discussão em 'Python' iniciado por Stack, Fevereiro 10, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to write code to output permutations. I do not understand why I am getting the TypeError? How to fix it? Thanks!

    A=[1,2,3]
    c=[]
    def perm(a):
    global c
    if len(a)==1:
    p=a
    else:
    for i in a:
    p=+perm(a.remove(i))
    c+=[p]
    return p
    perm(A)
    print(c)

    TypeError: object of type 'NoneType' has no len()

    Continue reading...

Compartilhe esta Página