python zip()函数
zip函数接受任意多个(包括0个和1个)序列作为参数,返回一个tuple列表。
例如:
1.示例代码:
1 #!/usr/local/env python3 2 ''' 3 Author:@南非波波 4 Blog:http://www.cnblogs.com/songqingbo/ 5 E-mail:qingbo.song@gmail.com 6 ''' 7 #zip()函数展示 8 x = [1,2] 9 y = [5,6] 10 xy = zip(x,y) 11 print(xy) #输出xy的值 <zip object at 0x01347A80> 12 print(type(xy)) #输出xy的类型 <class 'zip'> 13 print(dict(xy)) #输出xy转换成字典类型后的值 {1: 5, 2: 6}
1 #!/usr/local/env python2 2 >>> x = [1,2] 3 >>> y = [5,6] 4 >>> xy = zip(x,y) 5 >>> type(xy) 6 <type 'list'> 7 >>> print xy 8 [(1, 5), (2, 6)] 9 >>> print dict(xy) 10 {1: 5, 2: 6}
@南非波波
github:https://github.com/swht