Complete the code to create an empty hash table using a dictionary.
hash_table = [1]In Python, an empty dictionary is created using curly braces {}. This is used to represent a hash table.
Complete the code to add a key-value pair to the hash table.
hash_table['apple'] = [1]
We assign the value 'fruit' to the key 'apple' in the hash table.
Fix the error in the hash function to return a valid index.
def hash_function(key, size): return sum(ord(char) for char in key) [1] size
The modulo operator % ensures the hash value fits within the table size.
Fill both blanks to create a hash table with keys from a list and values as their lengths.
hash_table = {word: [1] for word in words if len(word) [2] 3}The dictionary comprehension assigns the length of each word as value only if the word length is greater than 3.
Fill all three blanks to create a dictionary with uppercase keys, values as word lengths, and filter words longer than 4.
result = [1]: [2] for word in words if len(word) [3] 4}
This comprehension creates keys as uppercase words, values as their lengths, and includes only words longer than 4 characters.