0
0
DSA Pythonprogramming~10 mins

Array Access and Update at Index in DSA Python - Interactive Practice

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

Complete the code to access the element at index 2 in the list.

DSA Python
my_list = [10, 20, 30, 40, 50]
print(my_list[[1]])
Drag options to blanks, or click blank then click option'
A2
B3
C1
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 3 instead of 2, which accesses the fourth element.
Using index 1, which accesses the second element.
2fill in blank
medium

Complete the code to update the element at index 1 to 99.

DSA Python
numbers = [5, 10, 15, 20]
numbers[[1]] = 99
print(numbers)
Drag options to blanks, or click blank then click option'
A0
B1
C2
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Updating index 0 instead of 1.
Using an index out of range.
3fill in blank
hard

Fix the error in the code to correctly update the last element to 100.

DSA Python
data = [1, 2, 3, 4, 5]
data[[1]] = 100
print(data)
Drag options to blanks, or click blank then click option'
A4
B-1
C5
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 5 which is out of range.
Using index -1 when positive index is expected.
4fill in blank
hard

Fill both blanks to access and update the middle element of the list.

DSA Python
arr = [10, 20, 30, 40, 50]
mid_index = len(arr) [1] 2
arr[mid_index] = [2]
print(arr)
Drag options to blanks, or click blank then click option'
A//
B/
C25
D30
Attempts:
3 left
💡 Hint
Common Mistakes
Using '/' which results in float index causing error.
Updating the middle element to wrong value.
5fill in blank
hard

Fill all three blanks to create a dictionary with keys as uppercase letters and values as elements greater than 10.

DSA Python
values = {'a': 5, 'b': 15, 'c': 25, 'd': 8}
result = { [1]: [2] for k, v in values.items() if v [3] 10}
print(result)
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'k' instead of 'k.upper()' for keys.
Using '<' instead of '>' in the condition.
Using keys as values or vice versa.