Mohammad Faizan Khan Mohammad Faizan Khan - 2 months ago 6
Python Question

How to run two loop simeltanously in one loop in python

Is there any way available to put two loops in one? I have:

for getFeature in layerNameValueGetObj.getFeatures():
for setFeature in layerNameValueSetObj.getFeatures():


I want to run
layerNameValueGetObj.getFeatures()
and
layerNameValueSetObj.getFeatures()
under one loop. How can I do this?

I don't want to nest them, I want to get both loop columns at a time.

Answer

You can use zip

for a, b in zip(list_a, list_b): 
    print a, b
Comments