0
0
Pythonprogramming~20 mins

Nested lists in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Nested Lists Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2:00remaining
Output of nested list indexing
What is the output of this Python code?
Python
matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
result = matrix[1][2]
print(result)
A6
B5
C4
DIndexError
Attempts:
2 left
๐Ÿ’ก Hint
Remember that indexing starts at 0 and matrix[1] is the second list.
โ“ Predict Output
intermediate
2:00remaining
Length of nested lists
What is the output of this code?
Python
nested = [[1, 2], [3, 4, 5], [6]]
length = len(nested[1])
print(length)
A1
B3
C2
DTypeError
Attempts:
2 left
๐Ÿ’ก Hint
len() returns the number of elements in the list at index 1.
โ“ Predict Output
advanced
2:00remaining
Output of nested list comprehension
What is the output of this code?
Python
matrix = [[i * j for j in range(3)] for i in range(3)]
print(matrix)
A[[0, 0, 0], [1, 1, 1], [2, 2, 2]]
B[[0, 1, 2], [0, 1, 2], [0, 1, 2]]
C[[0, 0, 0], [0, 1, 2], [0, 2, 4]]
DSyntaxError
Attempts:
2 left
๐Ÿ’ก Hint
Each element is i multiplied by j for j in 0 to 2, repeated for i in 0 to 2.
โ“ Predict Output
advanced
2:00remaining
Value after nested list modification
What is the value of nested[0][1] after running this code?
Python
nested = [[1, 2], [3, 4]]
nested[0][1] = nested[1][0]
print(nested[0][1])
A2
BIndexError
C4
D3
Attempts:
2 left
๐Ÿ’ก Hint
nested[1][0] is assigned to nested[0][1].
๐Ÿง  Conceptual
expert
2:00remaining
Error type from invalid nested list access
What error does this code raise?
Python
lst = [[1, 2], [3, 4]]
print(lst[2][0])
AIndexError
BTypeError
CAttributeError
DKeyError
Attempts:
2 left
๐Ÿ’ก Hint
Check if the outer list has an element at index 2.