Code Logo

Score Boost with map()

Published at22 Apr 2026
Python Functions Easy 0 views
Like0

A teacher wants to add a small bonus to a practice quiz before recording the final results. The original scores are already stored in a list of integers, and each student should receive exactly 5 extra points.

Your task is to return a new list where every score has been increased by 5. The order of the scores should stay the same, because each position still belongs to the same student as before.

For example, if the input is [60, 72, 88], the result should be [65, 77, 93]. If the list is empty, the answer should also be an empty list because there are no scores to update.

This challenge focuses on applying one simple transformation to every value in a collection. In Python, that pattern is often expressed with a small function passed into another function that handles the iteration.

Example Input & Output

Example 1
Input
scores = [95]
Output
[100]
Explanation

A one-item list still goes through the same +5 transformation.

Example 2
Input
scores = []
Output
[]
Explanation

An empty score list stays empty after mapping.

Example 3
Input
scores = [60, 72, 88]
Output
[65, 77, 93]
Explanation

Each score increases by 5 while keeping the original order.

Algorithm Flow

Recommendation Algorithm Flow for Score Boost with map()
Recommendation Algorithm Flow for Score Boost with map()

Solution Approach

This problem is a nice fit for map() because the same transformation needs to be applied to every element in the list. Nothing depends on neighboring values, and there is no filtering or reordering. Each score is simply turned into a new score by adding 5.

The job of map() is to take a function and apply it to every item in an iterable. So the first question is: what should that function do? In this case, it only needs to accept one score and return score + 5.

You can write that transformation inline with a lambda:

return list(map(lambda score: score + 5, scores))

That says, "for every score in the list, produce a new value that is 5 larger," and then convert the mapped result back into a list.

Another readable option is to define a small helper function and pass that into map(). That version is a little longer, but it highlights the idea that functions can be treated like values and handed to other functions to control behavior.

The key lesson here is not the arithmetic itself. It is the pattern of pairing a transformation function with map() so the code describes the operation at a higher level. Python still processes every score one by one, but the structure becomes very clear: transform each item, keep the order, return the resulting list.

The runtime is O(n) because each score is visited once, and the returned list uses O(n) space for the updated values.

Best Answers

python - Approach 1
def boost_scores(scores):
    def add_bonus(score):
        return score + 5
    return list(map(add_bonus, scores))