【发布时间】:2012-08-05 16:11:02
【问题描述】:
考虑以下代码 sn-p(注意我使用的是全局,因为非本地关键字在 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)
在哪里
some_string: A space delimited integers
some_number: An integer
len(some_string) = 4000 时,上述代码失败并报错
RuntimeError: maximum recursion depth exceeded while calling a Python object
是因为内部嵌套的生成器是递归实现的吗?
【问题讨论】:
标签: python recursion generator python-2.x