0
0
Data Structures Theoryknowledge~10 mins

Hash table applications in Data Structures Theory - Interactive Code Practice

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

Complete the code to create a hash table that stores key-value pairs.

Data Structures Theory
hash_table = [1]()
Drag options to blanks, or click blank then click option'
Adict
Bset
Clist
Dtuple
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using list instead of dict, which does not support key-value pairs.
Using set, which stores only unique values without keys.
2fill in blank
medium

Complete the code to check if a key exists in a hash table.

Data Structures Theory
if [1] in hash_table:
Drag options to blanks, or click blank then click option'
Aitem
Bindex
Ckey
Dvalue
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Checking for a value instead of a key.
Using an index which is not applicable in hash tables.
3fill in blank
hard

Fix the error in the code to add a key-value pair to the hash table.

Data Structures Theory
hash_table[[1]] = 'value'
Drag options to blanks, or click blank then click option'
A'key'
Bkey
Cvalue
Ditem
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using an unquoted key which causes a NameError.
Using a value as a key.
4fill in blank
hard

Fill both blanks to create a hash table comprehension that maps words to their lengths for words longer than 3 characters.

Data Structures Theory
{word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B<
C>
Dword
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using the word itself instead of its length as the value.
Using the wrong comparison operator in the condition.
5fill in blank
hard

Fill all three blanks to create a hash table that stores uppercase keys and their values only if the value is positive.

Data Structures Theory
{ [1]: [2] for [3], [2] in data.items() if [2] > 0 }
Drag options to blanks, or click blank then click option'
Akey.upper()
Bvalue
Ckey
Ditem
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using the same variable name for key and value.
Not converting keys to uppercase.
Using incorrect variable names in the loop.