2024-09-29 01:27:00 发布
网友
我有以下数据结构:
data = (['test1','test2','test3'], ['foo1','foo2','foo3'], ['bar1','bar2','bar3'])
我想遍历这个数据结构,并创建一个新的元组,将每个列表的位置1附加到元组中。我想用
(test1,foo1,bar1), (test2,foo2,bar2), (test3,foo3,bar3)
这是一个简单的^{}和argument unpacking:
print zip(*data)
例如:
>>> data = (['test1','test2','test3'],['foo1','foo2','foo3'],['bar1','bar2','bar3']) >>> zip(*data) [('test1', 'foo1', 'bar1'), ('test2', 'foo2', 'bar2'), ('test3', 'foo3', 'bar3')]
通过zip()解压:
另请参见:Unzipping and the * operator。你知道吗
这是一个简单的^{} 和argument unpacking:
例如:
通过zip()解压:
另请参见:Unzipping and the * operator。你知道吗
相关问题 更多 >
编程相关推荐