Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

zip python

# zip() Is Build In Function, For Combine Two Values Together
# If The Passed Iterators Have Different Lengths,
# The Iterator With The Least Items Decides The Length Of The New Iterator.

# And Of Course zip() Use With Iterator

# If We Have Tow tuples() Ane We Want Join Together Like :-

# Example :-

a = ("John", "Charles", "Mike")
b = ("Jenny", "Christy", "Monica", "Vicky")

together = zip( a, b )

for names in together :

	print( names ) 

# Will Print ==> ('John', 'Jenny')
#                ('Charles', 'Christy')
#                ('Mike', 'Monica')

print( "-" * 100 ) # Just Separator To Separate Them

# Now I Think You Say Why ( "Vicky" ) Not Print With Them,
# Because The First tuple() Have Just 3 
# If We Want Put ( "Vicky" ) We Need Append 
# Another Value In tuple() /a :-

a = ("John", "Charles", "Mike", "Victor")
b = ("Jenny", "Christy", "Monica", "Vicky")

together = zip( a, b )

for names in together :

	print( names )

# Will Print ('John', 'Jenny')
#            ('Charles', 'Christy')
#            ('Mike', 'Monica')
#            ('Victor', 'Vicky')

# As We See ( "Vicky" ) Has Append, With The New One ==> ( 'Victor' ).

# So The Summary Is, zip() Combine Two Values Together.

# Example With List :-

c = [ "Mido", "Mohamed", "Abdallah" ]
n = [  17, 28, 30  ]

t = zip( c, n )

for mylist in t :

	print( mylist )
    
# Will Print ==> ('Mido', 17)
#                ('Mohamed', 28)
#                ('Abdallah', 30)
Source by docs.python.org #
 
PREVIOUS NEXT
Tagged: #zip #python
ADD COMMENT
Topic
Name
1+6 =