如何在python中从数组中查找最小值和最大值?

我已经从API提取了数据并尝试执行一些计算。我能够获取值,但找不到最小值和最大值。

# importing libraries

import json
import requests

# loading data from BOM API
response = requests.get("http://www.bom.gov.au/fwo/IDN60701/IDN60701.94598.json")
bom_dict = json.loads(response.text)

press_collection = []

# extracting data

for values in bom_dict['observations']['data']:
    press_collection.append(values['press']) // got
this
press
from json

for val in range(len(press_collection)):

print("the pressure value is \n", press_collection[val])
#calculating minimum , maximum and average pressure

我是Python的新手。因此,需要帮助。

评论
  • 不开则待
    不开则待 回复

    如果press_collection仅包含数字数据(int,float等) 然后,您可以执行以下操作:

    min(press_collection) #minimum
    max(press_collection) #maximum
    sum(press_collection)/len(press_collection) #average