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

Answers for preliminary work #2

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

Conversation

Pete-R-Jones
Copy link

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

I initially found it difficult to read the file as I didn't realise it was already in a "json" format, so I was incorrectly using json.dumps. Once that was sorted it wasn't too bad and satisfying to see the result!

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

...
mags = [get_magnitude(quake) for quake in data]
max_value = max(mags)
index = mags.index(max_value)
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if there were more than one earthquakes with the same magnitude max_value? What would mags.index return then?

mags = [get_magnitude(quake) for quake in data]
max_value = max(mags)
index = mags.index(max_value)
return [max_value, get_location(data[index])]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since you know you will always be returning two items (the magnitude and location), you can also return a tuple, implicitly or explicitly:

return (max_value, get_location(data[index]))
# or
return max_value, get_location(data[index])

Returning a list is by no means wrong, though.

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.

2 participants