为什么此功能会导致最大重复错误?

MCP*_*tor 4 python python-2.7

我在使用codecademy.com时在python中有一个非常简单的函数.代码通过了练习,但它确实导致了最大的递归错误,我不明白为什么.这就是我所拥有的:

n = [3, 5, 7]

def double_list(x):
    for i in range(0, len(x)):
        x[i] = x[i] * 2
    return double_list(x)

print double_list(n)
Run Code Online (Sandbox Code Playgroud)

Tor*_*xed 6

因为double_list你在double_list再次打电话?

return double_list(x)
Run Code Online (Sandbox Code Playgroud)

这会导致你进入无限循环,除非你设置一个应该破坏的条件.

OP已经解决了,这是他的解决方案:

n = [3, 5, 7]

def double_list(x):
    for i in range(0, len(x)):
        x[i] = x[i] * 2
    return x

print double_list(n)
Run Code Online (Sandbox Code Playgroud)