Skip to content
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

Constance - Answers UCL-MPHY0021-21-22/RSE-Classwork#13 #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

claine18
Copy link

@claine18 claine18 commented Oct 26, 2021

Answers UCL-MPHY0021-21-22/RSE-Classwork#13
I found powerful to convert string into a dictionary with the json package.

Result obtained :

Loaded 120
The strongest earthquake was at [-2.15, 52.52] with magnitude 4.8

@claine18 claine18 changed the title Answers UCL-MPHY0021-21-22/RSE-Classwork#13 Constance - Answers UCL-MPHY0021-21-22/RSE-Classwork#13 Oct 26, 2021


def get_maximum(data):
"""Get the magnitude and location of the strongest earthquake in the data."""
...
list_magnitude = [get_magnitude(earthquake) for earthquake in data["features"]]
list_location = [get_location(earthquake) for earthquake in data["features"]]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really interesting to see list comprehensions put to use!

@@ -27,32 +28,38 @@ def get_data():
# To understand the structure of this text, you may want to save it
# to a file and open it in VS Code or a browser.
# See the README file for more information.
...
with open('response_web.json', 'w') as json_file:
json.dump(text, json_file, indent = 4)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea to use the indent argument, which gives a more readable output file. But are you writing what you need here? (there may be a related question on Moodle)

list_magnitude = [get_magnitude(earthquake) for earthquake in data["features"]]
list_location = [get_location(earthquake) for earthquake in data["features"]]
max_magnitude = max(list_magnitude)
max_location = list_location[list_magnitude.index(max_magnitude)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good! A question - what happens if there are two earthquakes with the same magnitude? What does list_magnitude.index return then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants