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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -