0
0
Pythonprogramming~10 mins

Nested lists in Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to access the first element of the first nested list.

Python
nested = [[1, 2], [3, 4]]
print(nested[1][0])
Drag options to blanks, or click blank then click option'
A[1]
B[0]
C[[0]]
D(0)
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using parentheses instead of square brackets.
Using the wrong index like [1] instead of [0].
2fill in blank
medium

Complete the code to print the length of the second nested list.

Python
nested = [[5, 6, 7], [8, 9]]
print(len(nested[1]))
Drag options to blanks, or click blank then click option'
A[1]
B[0]
C[2]
D1
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using index 0 instead of 1.
Trying to get length of the whole nested list instead of the inner list.
3fill in blank
hard

Fix the error in the code to correctly access the number 10 inside the nested list.

Python
numbers = [[4, 5], [6, 7, 8], [9, 10]]
print(numbers[1][1])
Drag options to blanks, or click blank then click option'
A[2]
B[3]
C[1]
D(2)
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using index 3 which is out of range.
Using parentheses instead of square brackets.
4fill in blank
hard

Fill both blanks to create a nested list with two inner lists, each containing numbers 1 to 3 and 4 to 6.

Python
nested = [[1], [2]]
print(nested)
Drag options to blanks, or click blank then click option'
A[1, 2, 3]
B[4, 5, 6]
C[7, 8, 9]
D[0, 1, 2]
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using wrong number ranges.
Putting numbers directly without lists.
5fill in blank
hard

Fill all three blanks to create a nested list comprehension that squares numbers 1 to 3 and 4 to 6 separately.

Python
nested_squares = [[x[1]2 for x in range([2], 4)], [x[1]2 for x in range(4, [3])] ]
print(nested_squares)
Drag options to blanks, or click blank then click option'
A**
B1
C4
D7
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using multiplication * instead of power **.
Wrong range start or end values.