Python tutorial
zip built-in function takes optional iterable objects as input, combines one element from each iterable, returns a tuple. This process continues untill shortest iterable exhausted. Zip is a Iterable objects, by default where element is a tuple.
zip has no elements
zip has one iterable argument
zip has two or more iterables arguments
>>>z = zip() >>>z
>>>z = zip('12345')
>>> z
>>> list(z)
[('1',), ('2',), ('3',), ('4',), ('5',)]
zip takes one element at a time from each iterable, combines them as a tuple.There are 5 elements from each list, zip returns five tupples to the list.
>>>student=["ram","mike","dick","jhon","swati"]
>>>scores=[90,30,60,90,55]
>>> z=zip(student,scores)
>>> list(z)
[('ram', 90), ('mike', 30), ('dick', 60), ('jhon', 90), ('swati', 55)]
>>>
>>>students=["ram","mike","dick","jhon","swati"]
>>>scores=[90,30,60,90,55]
>>>z=zip(students,scores)
>>>
>>>d=dict()
>>>
>>>for name,score in z:
d[name]=score
>>>
>>>d
{'ram': 90, 'mike': 30, 'dick': 60, 'jhon': 90, 'swati': 55}