TypeError: 'dict_keys' object is not callable

I have used the below program to get the maximum and minimum value in a dictionary. But, there is an type error.

my_dict = {‘x’:500, ‘y’:5874, ‘z’: 560}

key_max = max(my_dict.keys(), key=(lambda k: my_dict[k]))

key_min = min(my_dict.keys(), key=(lambda k: my_dict[k]))

print(‘Maximum Value: ‘,my_dict[key_max])

print(‘Minimum Value: ‘,my_dict[key_min])

(source – https://www.w3resource.com/python-exercises/dictionary/python-data-type-dictionary-exercise-15.php)

I am running this code on Jupyter notebook and getting the type error as the ‘dict.keys’ object is not callable.

The same code runs successfully on the pycharm.

Please advise me what changes should I make so that the code runs successfully on the jupyter notebook?
what is wrong in my code?code run on JupyterNBcode run on Pycharm successfully](https://i.stack.imgur.com/UntNd.png)

>Solution :

I have tested your program in Jupyter Notebook and the code is working just fine. Maybe you check for any typos. Hope this help

Code snippet run on jupyter notebook

Leave a Reply