Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
The community reviewed whether to reopen this question 2 years ago and left it closed:
Original close reason(s) were not resolved
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
您正在从同一列表中删除项目。
最好是只收集确实匹配的,然后返回这些:
添加几个调试打印件更清楚地显示出来:
它实际上永远不会检查
cccd
,因为您已经摆弄了列表上下文和迭代器跳过它。You're removing items from the same list you're iterating over.
Better would be to only collect the ones that do match, and return those:
adding a couple of debugging prints shows this more clearly:
It never actually checks
cccd
because you've fiddled with the list context and the iterator skips over it.您可以通过使用
任何()
函数与组合列表理解:You can solve the problem in one line by using
any()
function in combination with a composed list comprehension: