Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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]))

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading