Minimalist Python learning tutorial-----zip() function

The zip() function is used to pack the iterable objects into tuples, and then combine the tuples into a list to return.

ps:
(1) If the number of elements in each iterator is inconsistent, the length of the returned list is subject to the length of the shortest iterator.
(2) The difference between the zip() function in Python 2 and Python 3: In Python 3, the zip() function returns an object. Need to manually list () conversion.
See the code for details: (understand at a glance)

a = [1, 2, 3]
b = [4, 5, 6]
c = [4, 5, 6, 7, 8, 9]
d = list(zip(a, b))  #[(1, 4), (2, 5), (3, 6)]
e = list(zip(a, c))  #[(1, 4), (2, 5), (3, 6)] 元素个数以最短的列表长度为准

----------------------over-----------------------------

Guess you like

Origin blog.csdn.net/qq_28057379/article/details/106362857