0
0
DSA Pythonprogramming~10 mins

Arrays vs Other Data Structures When to Choose Arrays in DSA Python - Interactive Comparison Practice

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

Complete the code to create an array of size 5 initialized with zeros.

DSA Python
arr = [[1]] * 5
print(arr)
Drag options to blanks, or click blank then click option'
ANone
B0
C1
D''
Attempts:
3 left
💡 Hint
Common Mistakes
Using None instead of 0 will create an array of None values.
Using 1 will create an array of ones, not zeros.
2fill in blank
medium

Complete the code to access the third element of the array.

DSA Python
arr = [10, 20, 30, 40, 50]
print(arr[[1]])
Drag options to blanks, or click blank then click option'
A2
B1
C3
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 3 will access the fourth element, not the third.
Using index 1 will access the second element.
3fill in blank
hard

Fix the error in the code to append an element to the array.

DSA Python
arr = [1, 2, 3]
arr.[1](4)
print(arr)
Drag options to blanks, or click blank then click option'
Aextend
Badd
Cinsert
Dappend
Attempts:
3 left
💡 Hint
Common Mistakes
Using add() causes an error because lists do not have add method.
Using insert() requires two arguments, so it will cause an error here.
4fill in blank
hard

Fill both blanks to create a list of squares for numbers 1 to 5, but only include squares greater than 10.

DSA Python
squares = [x[1]2 for x in range(1, 6) if x[2]3]
print(squares)
Drag options to blanks, or click blank then click option'
A**
B%
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using % instead of ** will calculate remainder, not square.
Using < instead of > will filter wrong numbers.
5fill in blank
hard

Fill all three blanks to create a dictionary with keys as uppercase letters and values as their ASCII codes, but only for letters with ASCII code greater than 65.

DSA Python
result = { [1]: [2] for letter in ['a', 'B', 'C', 'd', 'E'] if ord(letter) [3] 65 }
print(result)
Drag options to blanks, or click blank then click option'
Aletter.upper()
Bord(letter)
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using letter instead of letter.upper() will keep keys in original case.
Using < instead of > will filter wrong letters.