0

if we want to zip a list with lists nested a another list e.g.

a = [1,2,3] 
b = [ ['a', 'b', 'c'], ['1', '2', '3']  ]
result = [ (1,'a', '1'), (2,'b','2'), (3,'c','3') ]

how can it be done efficiently giving the sizes of the lists can be huge? (i.e. we don't want to do b.append(c) beforehand then zip). thanks

1 Answer 1

2

Use * operator (See Python tutorial - Unpacking Argument Lists)

>>> a = [1,2,3]
>>> b = [ ['a', 'b', 'c'], ['1', '2', '3']  ]
>>> zip(a, *b)
[(1, 'a', '1'), (2, 'b', '2'), (3, 'c', '3')]
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.