Pythno ZIP function | Iterate multiple list in one time

 

ZIP () Function

Definition and Usage

The zip() function returns a zip object, which is an iterator of list or tuples where the first item in each passed iterator is paired together, and then the second item in each passed iterator are paired together etc.

If the passed iterators have different lengths, the iterator with the least items decides the length of the new iterator.

Syntax

zip(iterator1, iterator2, iterator3 ...)

Parameter Values

Parameter

Description

iterator1, iterator2, iterator3 ...

Iterator objects that will be joined together

Example

Join two list or tuples together:

a = ["John""Charles""Mike"]
b = [
"Jenny""Christy""Monica"]

x = 
zip(a, b)

Example

If one tuple contains more items, these items are ignored:

a = ["John""Charles""Mike"]
b = [
"Jenny""Christy""Monica""Vicky"]

x = 
zip(a, b)

Example

Join two list or tuples together with for loop:

a = ["John""Charles""Mike"]
b = [
"Jenny""Christy""Monica"]
t = len (a)

for x in range (t):

            print (a[x],b[x])

Example

Join two list or tuples together with for loop:

a = ["John""Charles""Mike"]
b = [
"Jenny""Christy""Monica"]
for  x,y in zip (a,b):

            print (x, y)

 <<Previous                                                  Next>>

कोई टिप्पणी नहीं

टिप्पणी: केवल इस ब्लॉग का सदस्य टिप्पणी भेज सकता है.

Send Multiple Emails From Excel | Send Bulk Mail from Excel Sheet with Attachment in One Click

Send Multiple Emails From Excel | Send Bulk Mail from Excel Sheet with Attachment in One Click Download VBA Code Notepad file - Click here D...

Blogger द्वारा संचालित.