Bird
Raised Fist0
Pythonprogramming~20 mins

List concatenation and repetition in Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
๐ŸŽ–๏ธ
List Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2: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)
A[1, 2, 3, 4, 1, 2, 3, 4]
B[1, 2, 3, 4, 3, 4, 1, 2]
C[1, 2, 3, 4, 3, 4]
D[1, 2, 3, 4, 4, 3]
Attempts:
2 left
๐Ÿ’ก Hint
Remember that list repetition happens before concatenation.
โ“ Predict Output
intermediate
2:00remaining
Result of repeated concatenation
What will be printed by this code?
Python
lst = [0]
lst = lst * 3 + [1]
print(lst)
A[0, 0, 0, 1]
B[0, 1, 0, 1]
C[0, 0, 1]
D[1, 0, 0, 0]
Attempts:
2 left
๐Ÿ’ก Hint
Check the order of operations: repetition then concatenation.
โ“ Predict Output
advanced
2:00remaining
Nested list repetition and concatenation output
What is the output of this code snippet?
Python
x = [[1]]
y = x * 3 + [[2]]
print(y)
A[[1], [1], [1], [2]]
B[[1, 1, 1], [2]]
C[[1], [2], [1], [1]]
D[[1], [1], [2], [1]]
Attempts:
2 left
๐Ÿ’ก Hint
List repetition duplicates references to the inner list.
โ“ Predict Output
advanced
2: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)
A[[0], [0], [0, 1]]
B[[0], [0, 1], [0]]
C[[0, 1], [0], [0]]
D[[0, 1], [0, 1], [0, 1]]
Attempts:
2 left
๐Ÿ’ก Hint
Remember that list repetition copies references, not the objects themselves.
๐Ÿง  Conceptual
expert
2:00remaining
Understanding list concatenation and repetition precedence
Which option correctly describes the result of this expression: [1] + [2] * 3?
AA list with two elements: [1, 6]
BA list starting with 1 followed by three 2's: [1, 2, 2, 2]
CA list with four elements all equal to 3: [3, 3, 3, 3]
DA list with three elements: [1, 2, 3]
Attempts:
2 left
๐Ÿ’ก Hint
Recall that repetition happens before concatenation.

Practice

(1/5)
1. What does the expression [1, 2] + [3, 4] do in Python?
easy
A. Creates a new list combining both lists: [1, 2, 3, 4]
B. Repeats the first list twice: [1, 2, 1, 2]
C. Creates a list of two lists: [[1, 2], [3, 4]]
D. Raises a TypeError because lists cannot be added

Solution

  1. Step 1: Understand the + operator with lists

    The + operator joins two lists into one new list containing all elements from both.
  2. Step 2: Apply + to [1, 2] and [3, 4]

    Joining these lists results in [1, 2, 3, 4].
  3. Final Answer:

    Creates a new list combining both lists: [1, 2, 3, 4] -> Option A
  4. Quick Check:

    List concatenation = combined list [OK]
Hint: Use + to join lists, not to repeat [OK]
Common Mistakes:
  • Thinking + repeats lists instead of joining
  • Confusing list concatenation with nesting
  • Expecting an error when adding lists
2. Which of the following is the correct syntax to repeat the list [5, 6] three times?
easy
A. [5, 6] ** 3
B. [5, 6] + 3
C. 3 + [5, 6]
D. [5, 6] * 3

Solution

  1. Step 1: Identify the operator for repetition

    The * operator repeats a list multiple times when used with an integer.
  2. Step 2: Check syntax correctness

    [5, 6] * 3 repeats the list three times: [5, 6, 5, 6, 5, 6].
  3. Final Answer:

    [5, 6] * 3 -> Option D
  4. Quick Check:

    List repetition uses * operator [OK]
Hint: Use * with list and number to repeat [OK]
Common Mistakes:
  • Using + instead of * for repetition
  • Trying to use ** which is invalid for lists
  • Confusing order of operands for repetition
3. What is the output of this code?
lst1 = [1]
lst2 = [2, 3]
result = lst1 * 2 + lst2 * 3
print(result)
medium
A. [1, 1, 2, 3, 2, 3, 2, 3]
B. [1, 2, 3, 1, 2, 3]
C. [1, 1, 2, 3, 3, 3]
D. [1, 1, 2, 3, 2, 3]

Solution

  1. Step 1: Calculate lst1 * 2

    Repeating [1] twice gives [1, 1].
  2. Step 2: Calculate lst2 * 3

    Repeating [2, 3] three times gives [2, 3, 2, 3, 2, 3].
  3. Step 3: Concatenate the two results

    Adding [1, 1] + [2, 3, 2, 3, 2, 3] results in [1, 1, 2, 3, 2, 3, 2, 3].
  4. Final Answer:

    [1, 1, 2, 3, 2, 3, 2, 3] -> Option A
  5. Quick Check:

    Repeat then join lists = combined repeated list [OK]
Hint: Repeat lists first, then add them [OK]
Common Mistakes:
  • Adding before repeating
  • Miscounting repeated elements
  • Confusing order of concatenation
4. Find the error in this code snippet:
list_a = [1, 2]
list_b = [3, 4]
result = list_a * list_b
print(result)
medium
A. No error, prints [1, 2, 3, 4]
B. SyntaxError due to missing parentheses
C. TypeError because * expects an integer, not a list
D. ValueError because lists cannot be multiplied

Solution

  1. Step 1: Understand list repetition rules

    List repetition uses * with an integer, not another list.
  2. Step 2: Identify the error in list_a * list_b

    Multiplying two lists causes a TypeError because the right operand must be int.
  3. Final Answer:

    TypeError because * expects an integer, not a list -> Option C
  4. Quick Check:

    List * list is invalid, needs int [OK]
Hint: Right side of * must be integer for list repetition [OK]
Common Mistakes:
  • Trying to multiply two lists directly
  • Expecting concatenation with * operator
  • Confusing syntax error with type error
5. You have two lists:
fruits = ['apple', 'banana']
veggies = ['carrot']
How do you create a new list that repeats the fruits twice and veggies three times, then combines them all in order?
hard
A. fruits * veggies * 5
B. fruits * 2 + veggies * 3
C. fruits + veggies * 5
D. (fruits + veggies) * 5

Solution

  1. Step 1: Repeat fruits and veggies separately

    fruits * 2 repeats fruits twice; veggies * 3 repeats veggies three times.
  2. Step 2: Concatenate the repeated lists

    Adding these repeated lists combines them in order as desired.
  3. Final Answer:

    fruits * 2 + veggies * 3 -> Option B
  4. Quick Check:

    Repeat separately then add lists [OK]
Hint: Repeat lists separately, then add [OK]
Common Mistakes:
  • Repeating combined list instead of separate lists
  • Using invalid multiplication of lists
  • Confusing order of operations