有没有办法迭代一个列表,但在迭代过程中从列表中删除/添加元素,但仍然迭代整个列表?

问题描述

示例:

for item in exampleList:
   exampleMethod(item) #method will add items to the exampleList
   exampleList.remove(item)

这个 foreach 循环需要遍历整个 exampleList,同时从 exampleList 添加删除项目。 整个 exampleList 我的意思是添加的元素。

我认为一种可能的方法是递归,但是,可以是一种更简单的方法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)