Python zip() 函数

a = [1,2,3] #此处可迭代对象为列表
b = [4,5,6]
c = [4,5,6,7,8]
zipped = zip(a,b)
print(zipped)
print(list(zipped))
print(list(zip(a,c)))
zipped = zip(a,b)
print(list(zip(*zipped))) #解压也使用list进行转换
<zip object at 0x000001C21DD8E588>
[(1, 4), (2, 5), (3, 6)]
[(1, 4), (2, 5), (3, 6)]
[(1, 2, 3), (4, 5, 6)]

http://www.waitingfy.com/archives/5011

5011

Leave a Reply

Name and Email Address are required fields.
Your email will not be published or shared with third parties.