Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 将2个列表列表连接到元组列表_Python 2.7_Tuples_List Comprehension - Fatal编程技术网

Python 2.7 将2个列表列表连接到元组列表

Python 2.7 将2个列表列表连接到元组列表,python-2.7,tuples,list-comprehension,Python 2.7,Tuples,List Comprehension,实现以下目标的有效方法是什么 发件人: 至: 一份清单就可以了。内置函数在每个迭代步骤中从每个列表返回一个元素,然后使用+操作符连接两个元素,最后通过调用内置函数将结果子列表转换为tuple 演示: aList = [[1, 2, 3], [2, 3, 4], [3, 4, 5], ...] bList = [['a'], ['b'], ['c'], ...] Out = [('a', 1, 2, 3), ('b', 2, 3, 4), ('c', 3, 4, 5), ....] In [4

实现以下目标的有效方法是什么

发件人:

至:


一份清单就可以了。内置函数在每个迭代步骤中从每个列表返回一个元素,然后使用
+
操作符连接两个元素,最后通过调用内置函数将结果子列表转换为tuple

演示:

aList = [[1, 2, 3], [2, 3, 4], [3, 4, 5], ...]
bList = [['a'], ['b'], ['c'], ...]
Out = [('a', 1, 2, 3), ('b', 2, 3, 4), ('c', 3, 4, 5), ....]
In [46]: aList = [[1, 2, 3], [2, 3, 4], [3, 4, 5]]

In [47]: bList = [['a'], ['b'], ['c']]

In [48]: Out = [tuple(b + a) for b, a in zip(bList, aList)]

In [49]: Out
Out[49]: [('a', 1, 2, 3), ('b', 2, 3, 4), ('c', 3, 4, 5)]