Python 'TypeError': 'Generator' object is not subscriptable
我尝试在python中执行一个简单的欧几里德示例,但收到了标题中提到的错误。代码如下:
1 2 3 4 5 | def gcd1(a,b): """ the euclidean algorithm""" while a: a, b = b%a, a return b |
我调用代码如下(我认为这可能与此有关):
1 2 | for x in set1: print(gcd1(x, set2[x])) |
编辑:现状(作品)
1 2 3 4 5 6 | set1 = list(range(start, end)) """ otherrange() behaves just like range() however returns a fixed list""" set2 = list(otherrange(start, end)) for x in set1: print(gcd1(x, set2[x])) |
这意味着
1 2 3 | set2_list = list(set2) for x in set1: print(gcd1(x, set2_list[x])) |