Skip to content
Foxipa
Code Completion 4 Challenges

Complete the Python Iterable Unpacking code

Practice exact unpacking, starred targets, nested targets, and value swapping.

Beginner ~6 min read

Challenge 1

Unpack the two coordinates into x and y.

python Your answer
point = (7, 9)
x, y = 
print(x + y)

Press Ctrl⌘Enter to check your answer

Challenge 2

Keep the first value separate and collect the remaining values in rest.

python Your answer
values = [10, 20, 30, 40]
first, *rest = 
print(first)
print(rest)

Press Ctrl⌘Enter to check your answer

Challenge 3

Unpack each record into name and score.

python Your answer
record = ("Grace", 25)

print(name, score)

Press Ctrl⌘Enter to check your answer

Challenge 4

Swap the two existing values without a temporary variable.

python Your answer
left = "red"
right = "blue"

print(left, right)

Press Ctrl⌘Enter to check your answer