如何从递归函数返回列表?

时间:2021-02-17 09:50:36

标签: python recursion

我正在尝试从以下递归函数返回一个列表,我应该在哪里做?。 我想我无法做到,因为我不完全了解所有功能步骤,所以我如何使用调试器跟踪递归的每个步骤? (pycharm) 谢谢各位热心的帮忙!!

def check_credentials(username, password):
    print("\nchecking credentials...\n")

    username_found = False
    password_found = False

    for profile in profiles["profiles"]:
        if profile["username"] == username:
            print(f"found username: {username}")
            username_found = True
            if profile["password"] == password:
                print(f"found password: {password}")
                password_found = True
                break

    if not username_found and not password_found:
        print("Wrong username and password, please try again.")
        login()
    elif not username_found:
        print("Wrong username, please try again.")
        login()
    elif not password_found:
        print("Wrong password, please try again.")
        login()

    profile_settings()

1 个答案:

答案 0 :(得分:1)

如果您需要从函数 #include<stdio.h> #include<string.h> #include<stdlib.h> int main() { char str[201],original[201]; fgets(str,201,stdin); int cnt=0,i,j=0,len=strlen(str); for(i=0;str[i]!='\0';i++){ if(str[i]=='W' && str[i+1]=='U' && str[i+2]=='B') { if(i!=0 && i!=len-3&&cnt==0&&j!=0) { original[j] = ' '; cnt++; j++; } i=i+2; } else { original[j] = str[i]; cnt=0; j++; } } original[j]='\0'; printf("%s",original); } 返回列表,您可以在其中创建一个列表变量并传递给 parentheses,然后返回该变量。这会起作用,因为您正在修改 parentheses_helper 内的同一个列表(列表没有被复制)

parentheses_helper