Python Practice › List Programs › Program 60

Zip two lists of lists

EasyList Programs · 60 of 100

Write a Python program to join two lists of lists item by item.

Advertisement
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

  1. zip the outer lists and concatenate each pair.

Solution

Python
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.

More list programs

← All 100 List Programs

Leave a Comment