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
I believe it has to do smth with args and kwargs which I am not familiar with, any explanation is welcome
Thanks,
解决方案
Use the *args argument expansion syntax:
zip(*big_list)
The * (splash) tells Python to take each element in an iterable and apply it as a separate argument to the function.
Demo:
>>> big_list = [['a1','b1','c1'], ['a2','b2','c3'], ['a3','b3','c3']]
>>> zip(*big_list)
[('a1', 'a2', 'a3'), ('b1', 'b2', 'b3'), ('c1', 'c3', 'c3')]