3

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,

1 Answer 1

5

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')]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.