iteration - Iterate elements on multiple python lists -


how can achieve iterate multiple lists in pythonic way?

say have 2 lists:

l1 = [1, 2, 3] l2 = [4, 5, 6] 

how can achieve iteration on whole set of elements in l1 , l2 without altering l1 , l2?

i can join both lists , iterate on result:

l3 = l1[:] l3.extend(l2) e in l3:   # ... whatever e 

but solution not sounds me pythonic, nor efficient, i'm looking better way.

you can directly iterate on l1 + l2:

>>> l1 = [1, 2, 3] >>> l2 = [4, 5, 6] >>>  >>> e in l1 + l2: ...     print e 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -