Yuxiang_Zhou group_dictionary operation#25
Open
zyxxyztp wants to merge 6 commits intoUCL-MPHY0021-21-22:mainfrom
Open
Yuxiang_Zhou group_dictionary operation#25zyxxyztp wants to merge 6 commits intoUCL-MPHY0021-21-22:mainfrom
zyxxyztp wants to merge 6 commits intoUCL-MPHY0021-21-22:mainfrom
Conversation
stefpiatek
reviewed
Oct 27, 2021
Collaborator
stefpiatek
left a comment
There was a problem hiding this comment.
Solid work, though looks like you've made your life harder by pulling out who has the value for each of the questions. Can just get the values using comprehension expressions?
| @@ -0,0 +1,3 @@ | |||
| { | |||
Collaborator
There was a problem hiding this comment.
in general, probably worth adding your .vscode directory to your gitignore
Comment on lines
+4
to
+10
| def max_age(group_information): | ||
| max_age = 0 | ||
| people = None | ||
| for key, value in group_information.items(): | ||
| if max_age < value['age']: | ||
| max_age = value['age'] | ||
| people = key |
Collaborator
There was a problem hiding this comment.
these all do work but can you do them in a comprehension expression. So for this function we could do (note: we're not asking for who has the maximum age, just what the maximum age is)
Suggested change
| def max_age(group_information): | |
| max_age = 0 | |
| people = None | |
| for key, value in group_information.items(): | |
| if max_age < value['age']: | |
| max_age = value['age'] | |
| people = key | |
| def max_age(group_information): | |
| ages = [person["age"] for person in group_information.values()] | |
| max_age = max(ages) |
| max_age = value['age'] | ||
| people = key | ||
|
|
||
| print("The older people of this group is " + people + " and the age is " + str(max_age)) |
Collaborator
There was a problem hiding this comment.
This is a perfect place for f strings, which let you format strings, even running code inline
Suggested change
| print("The older people of this group is " + people + " and the age is " + str(max_age)) | |
| print(f"The maximum age is {max(ages)}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Homework from UCL-MPHY0021-21-22/RSE-Classwork#12