Skip to content Skip to sidebar Skip to footer

Problem In Looping Two For Loops At The Same Time In Python

I want to execute two for loops at the same time in python, in order to read at the same time two lines with the same index in two different files. This is what i tried: def load_

Solution 1:

If you want to iterate over to iterators in one loop you should use zip()

for line_tp, line_lp in zip(tp, lp):

Solution 2:

You don't have two for loops at all here. As you should be able to tell from the error traceback, the error will be happening in the for statement itself; because this is not at all how you loop through two separate lists.

It's quite hard to tell what you are trying to do, but I suspect you meant this:

for line_tp, line_lp in zip(tp, lp):

Solution 3:

You can use zip to get lines from both files:

for line_tp,, line_lp in zip(tp, lp):
    ....

Post a Comment for "Problem In Looping Two For Loops At The Same Time In Python"