python-3.x - 迭代两个不同大小的列表
问题描述
import itertools
Value = ['178.217.107.8:53281', '91.90.191.238:8080', '27.116.51.114:8080']
content = ['link1','link2','link3']
for a,b in zip(Value , itertools.cycle(content)):
print(a,b)
我正在寻找的是,如果在第一个列表(代理列表)中假设任何代理不起作用然后传递并移动到列表中的下一个,并行内容列表中当前阶段的元素应该保持不变。
例如:对于第一个元素,输出为:178.217.107.8:53281 Link1
但是如果 178.217.107.8:53281 抛出错误,则将循环中的“a”值作为并将输出作为 91.90.191.238:8080 Link1
解决方案
伪代码如下:
list_of_proxies = ['178.217.107.8:53281', '91.90.191.238:8080', '27.116.51.114:8080']
list_of_links = ['link1','link2','link3']
for proxy in list_of_proxies:
for link in list_of_links:
# call some method to check if the proxy worked and store in a variable
success = method_call(proxy, link) # assuming return type as boolean
if !success:
break
else:
# remove the successful link from the list, depending on your exact requirement
list_of_links.remove(link)
推荐阅读
- php - 比较两个不同的数组返回空数组问题PHP
- azure-cognitive-services - Azure 认知语音 TTS 自定义日语非神经语音不可用
- python - Django Rest Framework: XLSXRenderer -- 如何检查查询集的条件并返回响应
- flutter - 在 Flutter 中显示本地通知时出错
- python-3.x - 必须放置源文件以使用子进程进行文件传输的默认目录应该是什么?
- mysql - MySQL 中的 INNER JOIN 和 EQUIJOIN 有什么区别?
- oracle - 如何将对象绑定到 Node Js 中的 Oracle 过程调用?
- typescript - 打字稿参数类型引用另一个参数
- google-cloud-firestore - GCP 数据存储突然极端数据不一致 (NDB 1.8.0)
- docker - Docker 不与 WSL 集成