yield的使用问题
通过下面的代码打印随机数from random import randint
def randGen(alist):
while len(alist) > 0:
yield alist.pop(randint(0,len(alist)))
for item in randGen(['rock','paper','scissors']):
print item
执行报错,错误提示: 错误提示:
yield alist.pop(randint(0,len(alist)))
IndexError: pop index out of range 本帖最后由 Linux_manne 于 2014-11-04 10:15 编辑
晕 你这个randint(0,len(alist)) 应该要减1阿
页:
[1]