Complete the code to create a hash table that stores key-value pairs.
hash_table = [1]()The dict type in Python is a built-in hash table that stores key-value pairs efficiently.
Complete the code to check if a key exists in a hash table.
if [1] in hash_table:
To check if a key exists in a hash table (dictionary), you use the key itself with the in keyword.
Fix the error in the code to add a key-value pair to the hash table.
hash_table[[1]] = 'value'
Keys in a hash table must be immutable and usually strings are used as keys. Here, the key should be a string literal, so it needs quotes.
Fill both blanks to create a hash table comprehension that maps words to their lengths for words longer than 3 characters.
{word: [1] for word in words if len(word) [2] 3}The comprehension maps each word to its length using len(word). The condition filters words longer than 3 characters using >.
Fill all three blanks to create a hash table that stores uppercase keys and their values only if the value is positive.
{ [1]: [2] for [3], [2] in data.items() if [2] > 0 }The comprehension uses key.upper() to make keys uppercase, value as the dictionary value, and iterates over key, value pairs from data.items(). The condition filters values greater than zero.