Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Append an item and extend a list

Learn how to add a single item to a list and then extend it with another iterable, returning the modified list.

Python practice6 minLists & TuplesBeginnerLast updated March 17, 2026

Problem statement

Write a function append_and_extend(lst, item, to_extend) that appends item to the end of lst and then extends lst with all elements from to_extend (an iterable). The function should modify the provided list and return it. Handle any iterable for to_extend (e.g., list, tuple, range). Do not create and return a new list — modify the original and return it.

Task

Implement a function that appends one element to a list and extends it with another iterable, returning the modified list.

Examples

Append and extend a list

Input

append_and_extend([1, 2], 3, [4, 5])

Output

[1, 2, 3, 4, 5]

First append 3 to [1, 2] -> [1, 2, 3], then extend with [4, 5] -> [1, 2, 3, 4, 5].

Input format

A function call: append_and_extend(lst, item, to_extend)

Output format

Return the modified list (the same object after changes).

Constraints

Do not create a new list; perform operations in-place (use append and extend semantics). to_extend can be any iterable.

Samples

Sample 1

Input

append_and_extend([], 'a', [])

Output

['a']

Appending 'a' to an empty list and extending with an empty iterable results in ['a'].