Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Problem No 10

Write a function that modifies a passed list

Easy

8 minute session

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.

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.

10:42 PM

Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.