0
0
DSA Pythonprogramming~10 mins

Hash Map vs Array vs Linked List for Lookup 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 get the value for key 'apple' from the dictionary.

DSA Python
fruits = {'apple': 5, 'banana': 3, 'orange': 2}
value = fruits[1]'apple'
print(value)
Drag options to blanks, or click blank then click option'
A[
B.get(
C('
D{
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of square brackets for dictionary access.
Using dot notation which doesn't work for dictionary keys.
2fill in blank
medium

Complete the code to find the index of value 7 in the list.

DSA Python
numbers = [3, 7, 1, 9]
index = numbers.[1](7)
print(index)
Drag options to blanks, or click blank then click option'
Aindex
Bfind
Csearch
Dlocate
Attempts:
3 left
💡 Hint
Common Mistakes
Using methods like find which do not exist for lists.
Trying to use search or locate which are not list methods.
3fill in blank
hard

Fix the error in the linked list traversal to print all node values.

DSA Python
class Node:
    def __init__(self, val):
        self.val = val
        self.next = None

head = Node(1)
head.next = Node(2)
head.next.next = Node(3)

current = head
while current is not None:
    print(current[1]val)
    current = current.next
Drag options to blanks, or click blank then click option'
A:
B->
C.
D[
Attempts:
3 left
💡 Hint
Common Mistakes
Using arrow -> which is not valid in Python.
Using brackets or colon which are invalid for attribute access.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths for words longer than 3 letters.

DSA Python
words = ['cat', 'house', 'dog', 'elephant']
lengths = {word: [1] for word in words if len(word) [2] 3}
print(lengths)
Drag options to blanks, or click blank then click option'
Alen(word)
B<
C>
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of > for filtering.
Not using len(word) for the value.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their counts for counts greater than 0.

DSA Python
data = {'apple': 2, 'banana': 0, 'cherry': 5}
result = {{ [1]: [2] for k, v in data.items() if v [3] 0 }}
print(result)
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using k.lower() instead of k.upper().
Filtering with == or < instead of >.