TypeError: 'dict_keys' object is not callable

Question:

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

I am running the below code on Jupyter notebook and getting the type error as the ‘dict.keys’ object is not callable. 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

Asked By: Priya Raut

||

Answers:

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

Answered By: Ronathan

Yup I can run your code perfectly too. Please try to simplify it like below.
It looks better too.

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

key_max = max(my_dict, key = my_dict.get)

key_min = min(my_dict, key = my_dict.get)

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

print('Minimum Value: ',my_dict[key_min])
Answered By: Sin Han Jinn
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.