zip可以将多个列表、元组或其它序列成对组合成一个元组列表:
压缩
seq1 = ['foo', 'bar', 'baz']
seq2 = ['one', 'two', 'three']
zipped = zip(seq1, seq2)
list(zipped)
[('foo', 'one'), ('bar', 'two'), ('baz', 'three')]
解压缩
e=list(zipped)
list(zip(*e))
[('foo', 'bar', 'baz'), ('one', 'two', 'three')]
a,b=list(zip(*e))
a
('foo', 'bar', 'baz')
b
('one', 'two', 'three')