This function returns a list of tuples, where the i-th tuple contains the i--th element from each of the Argument sequences or Iterables. The returned list is truncated in length to the length of the shortest argument sequence. When there was multiple arguments which is all of the same length, zip () was similar to map () with a in itial argument of None. With a single sequence argument, it returns a list of 1-tuples. With no arguments, it returns an empty list.
The left-to-right evaluation order of the iterables is guaranteed. This makes possible an idiom for clustering a data series into n-length groups using Zip (*[iter (s)]*n).
zip () in conjunction with the * operator can is used to unzip a list:
Pythonapi said above.
Here's your example:
x=[1,2,3]y=[4,5,6]z=[7,8,9]print zip (×)print zip (x, y) Print zip (x, y, z)
The result is:
[(1,), (2,), (3,)] [(1, 4), (2, 5), (3, 6) [(1, 4, 7), (2, 5, 8), (3, 6, 9)]
It can be seen that the zip is the same dimension of the data placed in a list
w= Zip (x, y, z)for in w: print'a:{0},b:{1},c:{2} '. Format (A,B,C)
The result is:
A:1,b:4,c:7A:2,b:5,c:8A:3,b:6,c:9
For is the output of each element in a tuple in the list
Print type (w), type (w[1])
' List ' ' tuple '>
x=[1,2,3]y=[4,5,6]z=[7,8,9]w= zip (x, y, z)print wPrint Zip (*w)
Results:
[(1, 4, 7), (2, 5, 8), (3, 6, 9)] [(1, 2, 3), (4, 5, 6), (7, 8, 9)]
This is zip (*w) is the function to return to just
Python zip function