Problem No 10
Write a function that modifies a passed list
Easy≈ 8 minute session
Lesson guide
What this Python exercise practices
Write a function that modifies a passed list is a beginner practice lesson that focuses on lists, iteration, filtering. It is designed to be solved in about 8 minutes with examples, starter code, and test feedback.
Prerequisites
- Python variables
- List values
- Basic indexing
Difficulty and time
- Level
- Beginner
- Estimated time
- 8 minutes
Practice path
Summary
Practice modifying a list passed into a function (in-place) and returning the updated list.
Problem statement
Write a function named append_value(lst, value) that takes a list lst and a value value, appends value to lst (modifying the original list), and returns the same list object with the new element added. Do not create and return a new list — modify the provided list in place.
Task
Implement a function that appends a value to a list argument, modifying it in-place and returning the modified list.
Examples
Append an integer
Input
append_value([1, 2], 3)
Output
[1, 2, 3]
Explanation
The function appends 3 to the provided list and returns the list with the new element.
Input format
A list (lst) and a single value (value) to append.
Output format
Return the same list with the new value appended (the printed representation of the list).
Constraints
Do not create a new list; modify lst in place and return it. The list can contain elements of any type.
Samples
Sample input 0
append_value(['a'], 'b')
Sample output 0
['a', 'b']
Explanation 0
The value 'b' is appended to the existing list.
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.
Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.