Menu

Sign in to track your progress and unlock all features.

Theme style

Log in
01. Keep only even numbers from a listE02. Transform each item in a listE03. Extract unique elements while keeping orderE

Problem No 2

Transform each item in a list

Easy

8 minute session

Summary

Apply a simple numeric transformation to each element and return a new list.

Problem statement

Write a function scale_list(nums, factor) that returns a new list where each number from nums is multiplied by factor. The function should not modify the original list. Support integers and floats for values and factor.

Task

Implement a function that multiplies every element in a list by a given factor.

Examples

Multiply by factor

Input

scale_list([1, 2, 3], 2)

Output

[2, 4, 6]

Explanation

Each element is multiplied by 2.

Input format

Two arguments: a list of numbers (ints or floats) and a numeric factor.

Output format

A list of numbers where each input element has been multiplied by the factor.

Constraints

Input list length up to a few thousand. Elements and factor are numeric types (int or float).

Samples

Sample input 0

[] , 5

Sample output 0

[]

Explanation 0

Empty list returns empty list regardless of factor.

Code editor
Loading editor…

AI assistant

Ask me anything!

Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.

Chat history is temporary and will not be saved.

03:44 PM

Free preview includes 1 Teach Theory response and 1 AI hint on each of the first 3 lessons in this module.