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

'int' object is not callable error in min function

I am trying to find the minimum value in this list. I started with a dictionary that looked like this:

temperature = {

    'June': [25,25,26,27,25,25,24,27,28,28,31,32,33],

    'July': [34,34,36,39,39,38,39,37,39,41,41,39,37],

    'August': [37,37,36,37,35,35,34,37,38,34,32,33,31],

}

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

and I went on to convert my values in a list using

val = (list(temperature.values()))

if I then use the min function to find the minimum value I get a <<‘int’ object is not callable>> message and this has also appeared in many other attempts. Could you explain what I am doing wrong?

>Solution :

This can help you out.

If you want the key and value that contain the min value, use this below

min(temperature.items(),key=lambda x :x[1])

which returns

('June', [25, 25, 26, 27, 25, 25, 24, 27, 28, 28, 31, 32, 33])

OR If you need the min value out of this list, use the code below

min(min(temperature.items(),key=lambda x :x[1])[1])

which returns:

24

To get only the key which can the minum value in the list, then use this below,

min(temperature.items(),key=lambda x :x[1])[0]

Output:

'June'
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