-
Notifications
You must be signed in to change notification settings - Fork 42
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
base: main
Are you sure you want to change the base?
Conversation
|
||
|
||
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"]] |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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)] |
There was a problem hiding this comment.
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?
Answers UCL-MPHY0021-21-22/RSE-Classwork#13
I found powerful to convert string into a dictionary with the json package.
Result obtained :