Building a List
~8 mincode completion
Write double_all(values) that returns a new list where every number has been doubled. Leave the input list unchanged.
For [1, 2, 3] it returns [2, 4, 6].
Examples
Each number comes back doubled
- Input
- double_all([1, 2, 3])
- Output
- [2, 4, 6]
Zero and negatives double correctly
- Input
- double_all([0, -4, 5])
- Output
- [0, -8, 10]
An empty list gives an empty list
- Input
- double_all([])
- Output
- []
Hints
Hint 1
Build the result up as you go, then return it.
Hint 2
Watch for this: modified input in place.
Requirements
: a list of numbers
Return a new list with each number doubled. The input is not modified.
Constraints
Standard library only, no imports required
Time limit: 200 ms, Memory: 64 MB
Where this shows up
~8 min
••••••••••••••••
8 employers weight this skill
3 quant funds, 2 frontier labs, 2 big tech firms, 1 AI product company. Top match scores 80.
Python
def double_all(values):
"""
Double every number in a list.
Args:
values: a list of numbers
Returns:
A new list with each number doubled. The input is not modified.
"""
# YOUR CODE HERE
pass