小编use*_*359的帖子

严重难以捉摸的循环(绞尽脑汁!)

我在Python 2.72中遇到了一个循环问题,这让我非常沮丧.基本上循环不是在第一个索引上迭代j,我已经尝试了各种方法来修复它而没有运气.

def learn(dataSet):
    for i in dataSet.getNext():
        recall = raw_input("Enter all members of %s you are able to recall >>> (separated by commas)  " % (i.getName()))
        missed = i.getMembers()     
        missedString = []       
        for a in missed:
            missedString.append(a.getName())    
Run Code Online (Sandbox Code Playgroud)

这是我无法迭代的循环.第一个for循环只经历j拆分字符串列表中的第一次迭代,然后从中删除它missedString.我希望recall删除split-string的所有成员missedString.

for j in string.split(recall, ','):
    if j in missedString:
        missedString.remove(j)
        continue
for b in missed:
    if b.getName() not in missedString:
        missed.remove(b)
print 'You missed %d.  ' % (len(missed))
if (len(missed)) > …
Run Code Online (Sandbox Code Playgroud)

python iteration for-loop python-2.7

1
推荐指数
1
解决办法
103
查看次数

标签 统计

for-loop ×1

iteration ×1

python ×1

python-2.7 ×1