Python 如何同时运行两个for循环并对输出进行决策

Python 如何同时运行两个for循环并对输出进行决策,python,python-3.x,multithreading,for-loop,Python,Python 3.x,Multithreading,For Loop,我试图在中同时运行两个for循环,并在每次传递中做出决定。循环搜索sql文件并获取每一行以进行比较 我试过把这个环编在一起,但运气不好。如果有人对如何执行此操作或如何实现多线程方法有建议。(我从未尝试过多线程) 如果我用if语句运行它,得到的结果将是来自for循环中最后一行的决定。我想做的是比较每一行并逐行做出决定。我认为您不需要多线程来获得所需的结果。只需将输出放入Python列表中,并使用enumerate函数循环: rows_list = [] perrows_list = [] for

我试图在中同时运行两个for循环,并在每次传递中做出决定。循环搜索sql文件并获取每一行以进行比较

我试过把这个环编在一起,但运气不好。如果有人对如何执行此操作或如何实现多线程方法有建议。(我从未尝试过多线程)


如果我用if语句运行它,得到的结果将是来自for循环中最后一行的决定。我想做的是比较每一行并逐行做出决定。

我认为您不需要多线程来获得所需的结果。只需将输出放入Python列表中,并使用enumerate函数循环:

rows_list = []
perrows_list = []

for row in rows:
    print(row)
    KnowNextRow = nextrowfinder(str(row))
    rows_list.append(KnowNextRow)

for perrow in perrows:
    PerfectNextRow = perrow
    xx = (str(PerfectNextRow))
    perrows_list.append(xx)
rows_len = len(rows_list)  #Get length of lists to ensure they are the same
perlen = len(perrows_list) 

for idx, item in enumerate(rows_list):
    if idx < (perlen - 1) # Check that perrows item exists
        if item == perrows_list[idx] 
            print("Rows Match At Row# " + idx) 
rows\u list=[]
perrows_列表=[]
对于行中的行:
打印(行)
KnowNextRow=nextrowfinder(str(row))
行\u列表。追加(KnowNextRow)
对于perrow中的perrow:
PerfectNextRow=perrow
xx=(str(PerfectNextRow))
perrows_list.append(xx)
rows_len=len(rows_list)#获取列表的长度以确保它们相同
perlen=len(perrows_列表)
对于idx,枚举(行列表)中的项:
如果idx<(perlen-1)#检查perrows项目是否存在
如果项==perrows_列表[idx]
打印(“行与行匹配”+idx)

是什么阻止您嵌套循环?您能否在问题中提供输入和预期输出?当我尝试此方法时,我收到一个列表超出范围错误。两个列表的长度是否相同?我编辑了代码以适应不同大小的列表。这就是我所能做的,而不必看到你的代码的其余部分。
rows_list = []
perrows_list = []

for row in rows:
    print(row)
    KnowNextRow = nextrowfinder(str(row))
    rows_list.append(KnowNextRow)

for perrow in perrows:
    PerfectNextRow = perrow
    xx = (str(PerfectNextRow))
    perrows_list.append(xx)
rows_len = len(rows_list)  #Get length of lists to ensure they are the same
perlen = len(perrows_list) 

for idx, item in enumerate(rows_list):
    if idx < (perlen - 1) # Check that perrows item exists
        if item == perrows_list[idx] 
            print("Rows Match At Row# " + idx)