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],
}
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'