Open
Conversation
Was only used for testing in pretty gui
stefpiatek
reviewed
Oct 26, 2021
Collaborator
stefpiatek
left a comment
There was a problem hiding this comment.
Nice work, some feedback for a bit of style and simplifying comprehension expressions
Comment on lines
+24
to
+28
| "NewGuyNoFriends": { | ||
| "age": 150, | ||
| "job": "student", | ||
| "relations": { | ||
| } |
| } | ||
|
|
||
| # the maximum age of people in the group | ||
| max_age = max([group.get(personName).get("age") for personName in group.keys()]) |
Collaborator
There was a problem hiding this comment.
You could simplify the base of your list comprehension a little bit by using the values directly
Suggested change
| max_age = max([group.get(personName).get("age") for personName in group.keys()]) | |
| max_age = max(person.get("age") for person in group.values()) |
| print("oldest person is", max_age) | ||
|
|
||
| # the average (mean) number of relations among members of the group | ||
| import numpy as np |
Collaborator
There was a problem hiding this comment.
some style feedback: you should have all import statements at the start of your script
| print("mean number of relations is", mean_relations) | ||
|
|
||
| # the maximum age of people in the group that have at least one relation | ||
| max_non_relationless = max([group.get(personName).get("age") for personName in group.keys() if len(group.get(personName).get("relations")) != 0]) |
Collaborator
There was a problem hiding this comment.
could also use the inherent "falsyness" of an empty dictionary
Suggested change
| max_non_relationless = max([group.get(personName).get("age") for personName in group.keys() if len(group.get(personName).get("relations")) != 0]) | |
| max_non_relationless = max([group.get(personName).get("age") for personName in group.keys() if group.get(personName).get("relations")]) |
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.
Used the sample friend group representation, added one person with no relations to be able to answer the question: "NewGuyNoFriends".
Curious to know if trees/relationship ideas are consistently best represented by dicts. Of course there are other ways that may be be better in some circumstances, but generally, are dicts the best?
UCL-MPHY0021-21-22/RSE-Classwork#12