Skip to content

Initial commit #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions Start/Ch_1/minmax.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))