Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Add two lists elementwise with map

Use map and a lambda to add two lists elementwise, returning a list of sums up to the shortest input.

Python practice14 minFunctions as Objects (Lambda, Map/Filter)IntermediateLast updated March 20, 2026

Problem statement

Given two lists of numbers, return a new list where each element is the sum of the elements at the same index in the two input lists. Stop at the length of the shorter list (i.e., do not fill missing values). Implement this using map and a lambda function.

Task

Write a function that uses map (and a lambda) to add corresponding elements of two lists together.

Examples

Basic elementwise addition

Input

add_lists([1, 2, 3], [4, 5, 6])

Output

[5, 7, 9]

1+4, 2+5, 3+6 => [5,7,9]

Input format

Two lists of numbers, e.g. [1, 2, 3] and [4, 5, 6].

Output format

A list of numbers containing pairwise sums, as a Python list.

Constraints

Both inputs are iterable sequences of numeric types (ints or floats). Behavior: stop at the shorter length.

Samples

Sample 1

Input

add_lists([1, 2], [10, 20, 30])

Output

[11, 22]

Only the first two pairs are summed.