Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 144 characters in body
Source Link
NPatel
  • 21.4k
  • 17
  • 104
  • 166

You can use zip to iterate over 2 list.

>>> list1 = [ 'one', 'two', 'three' ] >>> list2 = [ 'I', 'II', 'III', 'IV', 'V' ] >>> for (x, y) in zip(list1, list2): ... print x + " from list1" ... print y + " from list2" ... one from list1 I from list2 two from list1 II from list2 three from list1 III from list2 

Note: zip will provide till the list which is small. So in your case, list1 has 3 element and list2 has 5 elements, so zip will give data till 3 elements only. you can use izip_longest to reach all element in list2

You can use zip to iterate over 2 list.

>>> list1 = [ 'one', 'two', 'three' ] >>> list2 = [ 'I', 'II', 'III', 'IV', 'V' ] >>> for (x, y) in zip(list1, list2): ... print x + " from list1" ... print y + " from list2" ... one from list1 I from list2 two from list1 II from list2 three from list1 III from list2 

Note: zip will provide till the list which is small. So in your case, list1 has 3 element and list2 has 5 elements, so zip will give data till 3 elements only.

You can use zip to iterate over 2 list.

>>> list1 = [ 'one', 'two', 'three' ] >>> list2 = [ 'I', 'II', 'III', 'IV', 'V' ] >>> for (x, y) in zip(list1, list2): ... print x + " from list1" ... print y + " from list2" ... one from list1 I from list2 two from list1 II from list2 three from list1 III from list2 

Note: zip will provide till the list which is small. So in your case, list1 has 3 element and list2 has 5 elements, so zip will give data till 3 elements only. you can use izip_longest to reach all element in list2

added 12 characters in body
Source Link
NPatel
  • 21.4k
  • 17
  • 104
  • 166

You can use zip to iterate over 2 list.

>>> list1 = [ 'one', 'two', 'three' ] >>> list2 = [ 'I', 'II', 'III', 'IV', 'V' ] >>> for (x, y) in zip(list1, list2): ... print x + " from list1" ... print y + " from list2" ... one from list1 I from list2 two from list1 II from list2 three from list1 III from listlist2 

2

Note: zip will provide till the list which is small. So in your case, list1 has 3 element and list2 has 5 elements, so zip will give data till 3 elements only.

You can use zip to iterate over 2 list.

>>> for (x, y) in zip(list1, list2): ... print x + " from list1" ... print y + " from list2" ... one from list1 I from list2 two from list1 II from list2 three from list1 III from list 

2

Note:

You can use zip to iterate over 2 list.

>>> list1 = [ 'one', 'two', 'three' ] >>> list2 = [ 'I', 'II', 'III', 'IV', 'V' ] >>> for (x, y) in zip(list1, list2): ... print x + " from list1" ... print y + " from list2" ... one from list1 I from list2 two from list1 II from list2 three from list1 III from list2 

Note: zip will provide till the list which is small. So in your case, list1 has 3 element and list2 has 5 elements, so zip will give data till 3 elements only.

added 12 characters in body
Source Link
NPatel
  • 21.4k
  • 17
  • 104
  • 166

You can use zip to iterate over 2 list.

>>> list1 = [ 'one', 'two', 'three' ] >>> list2 = [ 'I', 'II', 'III', 'IV', 'V' ] >>> for (x, y) in zip(list1, list2): ... print x + " from list1" ... print y + " from list2" ... one from list1 I from list2 two from list1 II from list2 three from list1 III from list 

2

Note:

You can use zip to iterate over 2 list.

>>> list1 = [ 'one', 'two', 'three' ] >>> list2 = [ 'I', 'II', 'III', 'IV', 'V' ] >>> for (x, y) in zip(list1, list2): ... print x ... print y ... one I two II three III 

Note:

You can use zip to iterate over 2 list.

>>> for (x, y) in zip(list1, list2): ... print x + " from list1" ... print y + " from list2" ... one from list1 I from list2 two from list1 II from list2 three from list1 III from list 

2

Note:

Source Link
NPatel
  • 21.4k
  • 17
  • 104
  • 166
Loading