Python Practice › List Programs › Program 60
Zip two lists of lists
Write a Python program to join two lists of lists item by item.
Input
[[1, 3], [5, 7], [9, 11]], [[2, 4], [6, 8], [10, 12, 14]]
Output
[[1, 3, 2, 4], [5, 7, 6, 8], [9, 11, 10, 12, 14]]
Approach
zipthe outer lists and concatenate each pair.
Solution
a = [[1, 3], [5, 7], [9, 11]]b = [[2, 4], [6, 8], [10, 12, 14]]print([x + y for x, y in zip(a, b)])Output
[[1, 3, 2, 4], [5, 7, 6, 8], [9, 11, 10, 12, 14]]
Learn the concept
New to this topic? Read the lesson, then come back.