Cor*_*bjn 2 python loops if-statement while-loop
我有一个带有 id 的列表(列表)。作为使用 wget 进行在线检查的结果,该列表的每个元素都返回字符串“true”或“false”。我想遍历该列表,只要有一个元素返回“false”值。基本上我想重复这一点:
for i in range(len(list)):
wget online check
if status == 'true':
write id to another list
elif status == 'false':
continue
time.sleep()
Run Code Online (Sandbox Code Playgroud)
一遍又一遍,直到一切都是真的。
我用嵌套的 while 循环尝试了它:
for j in range(len(list)):
while status_ == 'false':
wget online check
if status == 'true':
write id to another list
elif status == 'false':
continue
time.sleep()
Run Code Online (Sandbox Code Playgroud)
但这不起作用。有人可以帮忙吗?
干杯
使用 adeque作为旋转队列,当它成功时从双端队列中删除一个值。只要deque不为空,循环就会继续。
(双端队列就像一个列表,但您可以有效地向任一端添加或删除元素。)
from collections import deque
d = deque(list)
while d:
i = d.popleft()
wget online check
if status == "true":
write id to another list
else:
d.append(i) # Put it back to try again later
time.sleep(...)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
63 次 |
| 最近记录: |