Python Zip() function - Takes iterable elements as input, and returns iterator
Python zip is a container that holds real data inside. Python zip function takes iterable elements as input, and returns iterator. If Python zip function gets no iterable elements, it returns an empty iterator.
if we pass two iterable object of same lengths, then an iterable of python tuple will be returned where each element of the tuple will be from those iterable lists.
Python zip function is mainly used to combining data of two iterable elements together. See the following code.
alphabet_list = list(string.ascii_letters)
lst=zip(alphabet_list[0::2],alphabet_list[1::2])
for i in lst:
print(i)
Output :
('a', 'b')
('c', 'd')
('e', 'f')
('g', 'h')
...continue
Comments
Post a Comment