在 django 的列表中创建一种特殊类型的合并列表
我确信这很容易做到,但我不知道该怎么做。
我有三个列表:list1=[a1, a2, a3...]
、list2=[b1, b2, b3...]
和 list3 =[c1, c2, c3...]
我想传递一个由这三个项目逐项合并的列表:
finalList = [[a1, b1, c1,], [a2, b2,c2], [a3, b3, c3]...]
我该怎么做?
I'm sure that this is pretty easy to do but I'm not sure how to do it.
I have three lists: list1=[a1, a2, a3...]
, list2=[b1, b2, b3...]
, and list3=[c1, c2, c3...]
I want to pass a list that is a by-item merger of these three:
finalList = [[a1, b1, c1,], [a2, b2, c2], [a3, b3, c3]...]
How do I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是内置的
zip()
的作用for:请注意,
final_list
实际上是一个元组列表,其长度将是最短输入列表的长度。函数
itertools.izip()
和itertools.izip_longest()
也值得注意。That's what the built-in
zip()
is for:Note that
final_list
will actually be a list of tuples, and its length will be the length of the shortest input list.The functions
itertools.izip()
anditertools.izip_longest()
are also noteworthy.