Reputation: 2147
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
Upvotes: 0
Views: 2267
Reputation: 369054
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')]
Upvotes: 2