Mohammad Faizan Khan Mohammad Faizan Khan - 1 year ago 68
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
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 Source

You can use zip

for a, b in zip(list_a, list_b): 
    print a, b
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download