gpt4 book ai didi

python - 如何在python中一个一个地遍历两个列表中的项目

转载 作者:行者123 更新时间:2023-12-01 23:25:11 26 4
gpt4 key购买 nike

我试图遍历包含两个不同用户的两个列表,当两个列表中都有项目时 for 循环有效,但当其中一个列表没有任何项目时它不会工作。

customer_list = [["ctm1","Jackson","abc"],["ctm2","Kaijun","edf"]]
admin_list = [["adm1","Jackson","martinez"],["adm2","Littsen","Lit"]]

for customer,admin in zip(customer_list, admin_list):
print(customer,admin)

admin_list 中没有项目

customer_list = [["ctm1","Jackson","abc"],["ctm2","Kaijun","edf"]]
admin_list = []

for customer,admin in zip(customer_list, admin_list):
print(customer,admin)

最佳答案

只需要实现一些if。示例

a=[]

if a:

放在你的列表之后但在你的之前

关于python - 如何在python中一个一个地遍历两个列表中的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67380488/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com