简体   繁体   English

在Python中列出列表中的列表

[英]Zipping lists within a list in Python

I have a list of lists 我有一份清单清单

big_list = [['a1','b1','c1'], ['a2','b2','c3'], ['a3','b3','c3']]

how do I zip the lists within this list? 如何压缩此列表中的列表?

what I want to do is zip(list1,list2,list3) , but do this dynamically 我想要做的是zip(list1,list2,list3) ,但动态地这样做

I believe it has to do smth with args and kwargs which I am not familiar with, any explanation is welcome 我相信它必须与我不熟悉的argskwargs有关,任何解释都是受欢迎的

Thanks, 谢谢,

Use the *args argument expansion syntax: 使用*args参数扩展语法:

zip(*big_list)

The * (splash) tells Python to take each element in an iterable and apply it as a separate argument to the function. * (splash)告诉Python将每个元素放在一个iterable中,并将其作为函数的单独参数应用。

Demo: 演示:

>>> big_list = [['a1','b1','c1'], ['a2','b2','c3'], ['a3','b3','c3']]
>>> zip(*big_list)
[('a1', 'a2', 'a3'), ('b1', 'b2', 'b3'), ('c1', 'c3', 'c3')]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM