0
0
DSA Pythonprogramming~10 mins

Why Hash Map Exists and What Problem It Solves in DSA Python - Test Your Knowledge

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

Complete the code to create a dictionary that stores a person's age.

DSA Python
person_age = {'Alice': [1]
Drag options to blanks, or click blank then click option'
Aage
B'25'
C25
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the number, making it a string instead of a number.
2fill in blank
medium

Complete the code to check if 'Bob' is in the dictionary keys.

DSA Python
if [1] in person_age:
Drag options to blanks, or click blank then click option'
ABob
B'Bob'
Cperson_age
D'Alice'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around 'Bob', causing a NameError.
3fill in blank
hard

Fix the error in the code to add a new key-value pair to the dictionary.

DSA Python
person_age[[1]] = 30
Drag options to blanks, or click blank then click option'
A'Charlie'
B30
Cage
Dperson_age
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number or variable name instead of a string key.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps names to ages for people older than 20.

DSA Python
{ [1]: [2][[1]] for [1] in [2] if [2][[1]] > 20 }
Drag options to blanks, or click blank then click option'
Aname
Bage
Cpeople
Dperson
Attempts:
3 left
💡 Hint
Common Mistakes
Using the dictionary name as key or wrong variable names.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that stores uppercase names as keys and ages as values for people aged 18 or older.

DSA Python
{ [1]: [2] for [3] in people if people[[3]] >= 18 }
Drag options to blanks, or click blank then click option'
Aname.upper()
Bpeople[name]
Cname
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names or forgetting to uppercase keys.