一行代码把包含二元组的列表拆成两个列表

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhonglongshen/article/details/88125114
a = [1,2,3,4]
b = ['x','y','x','w']
c = list(zip(a,b))
print(c)

輸出:

[(1, 'x'), (2, 'y'), (3, 'x'), (4, 'w')]
c = [(1, 'x'), (2, 'y'), (3, 'x'), (4, 'w')]
a,b = zip(*c)
print(a,b)

輸出:

(1, 2, 3, 4) ('x', 'y', 'x', 'w')

猜你喜欢

转载自blog.csdn.net/zhonglongshen/article/details/88125114
今日推荐