基本上,我需要一种方法,在满足某个条件时,返回到 for 循环的开头并重新开始整个迭代过程。
我要做的是这样的:
for index, item in enumerate(list2):
if item == '||' and list2[index-1] == '||':
del list2[index]
*<some action that resarts the whole process>*
这样,如果 ['berry','||','||','||','pancake] 在列表中,我最终得到的将是:
['berry','||','pancake']。
谢谢!
while something: for ...
?如果是的话,有什么复杂的地方吗?请发布一个代码示例以展示你正在做什么。 - S.Lott