首页 > 解决方案 > 如何在python中的double for循环中进行迭代

问题描述

我只想在第一次迭代中从 token1_list 和 token2_list 中获取第一个元素,在第二次迭代中获取第二个元素。目前在第一次迭代中,它正在从我的列表中获取所有元素,有没有办法解决这个问题?

char_list = []
for i in line_list:
    case1test = case1[int(i)-1]
    case1test1 = case1test.split()
    [char_list.append(case1test1[int(a):int(b)+1]) for a in token1_list for b in token2_list]

标签: pythonloopsfor-loop

解决方案


推荐阅读