Python learning zip function

The zip () function takes an iterable object as a parameter, packs the corresponding elements in the object into tuples, and then returns a list of these tuples.
If the number of elements in each iterator is inconsistent, the length of the returned list is the same as the shortest object. Using the * operator, the tuple can be decompressed into a list.

The zip method is different in Python 2 and Python 3: In Python 3.x, to reduce memory, zip () returns an object. If you want to display the list, you need to manually list () conversion

a = [1,2,3]
b = [4,5,6]
c = zip(a,b)
print(type(c))
print (c)
for v in c:
    print(v)

The results are as follows
Insert picture description here

Published 56 original articles · Like9 · Visit 1305

Guess you like

Origin blog.csdn.net/qq_29983883/article/details/105650064