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]
天哪。我怎么会错过这个!!!非常感谢。我想我今天已经有足够的代码了!!我应该休息。