Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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 有没有更好的方法来迭代列表以生成元组列表_Python_List_Tuples_Zip_Itertools - Fatal编程技术网

Python 有没有更好的方法来迭代列表以生成元组列表

Python 有没有更好的方法来迭代列表以生成元组列表,python,list,tuples,zip,itertools,Python,List,Tuples,Zip,Itertools,我有一个列表L=['a','B','C','D','E'] 变量x='Name',y='Age' 我想用这段代码把它们合并到元组列表中 from itertools import cycle list(zip(L, cycle([x]) , cycle([y]))) 这是我得到的输出,也是我想要的输出 [('A', 'Name', 'Age'), ('B', 'Name', 'Age'), ('C', 'Name', 'Age'), ('D', 'Name', 'Age'), ('E'

我有一个列表
L=['a','B','C','D','E']
变量
x='Name',y='Age'

我想用这段代码把它们合并到元组列表中

from itertools import cycle    
list(zip(L, cycle([x]) , cycle([y])))
这是我得到的输出,也是我想要的输出

[('A', 'Name', 'Age'), ('B', 'Name', 'Age'), ('C', 'Name', 'Age'), ('D', 'Name', 'Age'), ('E', 'Name', 'Age')]

但我想知道,有没有更好的方法

这样行吗,还是我错过了什么

[(l, x, y) for l in L]

天哪。我怎么会错过这个!!!非常感谢。我想我今天已经有足够的代码了!!我应该休息。