Abh*_*jit 1 python recursion generator python-2.x
请考虑以下代码段(注意我使用的是全局,因为Python 2.7中没有非本地关键字)
def foo(L,K):
global count
count = 0
def bar(f,L):
global count
for e in L:
if e - f == K or f - e == K: count += 1
yield e
try:
while True:
L = bar(L.next(),L)
except StopIteration:
return count
count=0
print foo((int(e) for e in some_string.split()),some_number)
Run Code Online (Sandbox Code Playgroud)
哪里
some_string: A space delimited integers
some_number: An integer
Run Code Online (Sandbox Code Playgroud)
何时len(some_string) = 4000,上述代码因错误而失败
RuntimeError: maximum recursion depth exceeded while calling a Python object
Run Code Online (Sandbox Code Playgroud)
是因为内部嵌套的生成器被实现为递归吗?
| 归档时间: |
|
| 查看次数: |
252 次 |
| 最近记录: |