Challenge - 5 Problems
List Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of list concatenation and repetition
What is the output of the following Python code?
Python
a = [1, 2] b = [3, 4] c = a + b * 2 print(c)
Attempts:
2 left
๐ก Hint
Remember that list repetition happens before concatenation.
โ Incorrect
The expression b * 2 repeats list b twice, resulting in [3, 4, 3, 4]. Then a + (b * 2) concatenates [1, 2] with [3, 4, 3, 4].
โ Predict Output
intermediate2:00remaining
Result of repeated concatenation
What will be printed by this code?
Python
lst = [0] lst = lst * 3 + [1] print(lst)
Attempts:
2 left
๐ก Hint
Check the order of operations: repetition then concatenation.
โ Incorrect
lst * 3 repeats [0] three times: [0, 0, 0]. Then adding [1] results in [0, 0, 0, 1].
โ Predict Output
advanced2:00remaining
Nested list repetition and concatenation output
What is the output of this code snippet?
Python
x = [[1]] y = x * 3 + [[2]] print(y)
Attempts:
2 left
๐ก Hint
List repetition duplicates references to the inner list.
โ Incorrect
x * 3 creates a list with three references to [1]. Adding [[2]] appends another list. The final list has four elements: three [1] lists and one [2] list.
โ Predict Output
advanced2:00remaining
Effect of list repetition on mutable elements
What will be the output after running this code?
Python
lst = [[0]] * 3 lst[0].append(1) print(lst)
Attempts:
2 left
๐ก Hint
Remember that list repetition copies references, not the objects themselves.
โ Incorrect
All three elements in lst refer to the same inner list. Appending 1 to lst[0] affects all three references.
๐ง Conceptual
expert2:00remaining
Understanding list concatenation and repetition precedence
Which option correctly describes the result of this expression: [1] + [2] * 3?
Attempts:
2 left
๐ก Hint
Recall that repetition happens before concatenation.
โ Incorrect
The expression [2] * 3 creates [2, 2, 2]. Then [1] + [2, 2, 2] concatenates to [1, 2, 2, 2].