From 22891b1b05d8a4c42c6141278dc2b1783e71bded Mon Sep 17 00:00:00 2001 From: Vladimir Belony <109683266+hgh23@users.noreply.github.com> Date: Sat, 24 Aug 2024 00:34:02 +0000 Subject: [PATCH] Initial commit --- Start/Ch_1/minmax.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/Start/Ch_1/minmax.py b/Start/Ch_1/minmax.py index f07afcc..41cef24 100644 --- a/Start/Ch_1/minmax.py +++ b/Start/Ch_1/minmax.py @@ -9,14 +9,29 @@ # TODO: The min() function finds the minimum value - +#print(f"The minimum value is: {min(values)}") +#print(f"The minimum value is: {min(strings)}") # TODO: The max() function finds the maximum value - +#print(f"The maximum value is: {max(values)}") +#print(f"The maximum value is: {max(strings)}") # TODO: define a custom "key" function to extract a data field - +#print(f"The minimum value is: {min(values, key=len)}") +#print(f"The minimum value is: {max(strings, key=len)}") # TODO: open the data file and load the JSON -# with open("../../30DayQuakes.json", "r") as datafile: -# data = json.load(datafile) +with open("/workspaces/advanced-python-working-with-data-4312001/30DayQuakes.json", "r") as datafile: + data = json.load(datafile) + +print(data["metadata"]["title"]) +print(len(data["features"])) + +def getmag(dataitem): + magnitude = dataitem["properties"]["mag"] + if (magnitude is None): + magnitude = 0 + return float(magnitude) + +print(min(data["features"], key=getmag)) +print(max(data["features"], key=getmag)) \ No newline at end of file