I’m encountering a TypeError in my Python code, and I’m unsure how to resolve it. The error message is:
TypeError: 'NoneType' object is not subscriptable
Here’s the relevant portion of my code
def get_value(dictionary, key):
return dictionary[key]
my_dict = None
result = get_value(my_dict, 'some_key')
print(result)
I’ve checked if my_dict is assigned correctly, but I’m not sure where it should be initialize and also I tried adding a check before calling get_value, but the error persists.
I expect the function to return the value associated with the provided key from the dictionary, but I’m getting a TypeError because None is not subscriptable.
1