Class based unfinished approach#14
Class based unfinished approach#14SolemnShark871 wants to merge 4 commits intoUCL-MPHY0021-21-22:mainfrom
Conversation
| @@ -2,4 +2,20 @@ | |||
|
|
|||
| # Your code to go here... | |||
There was a problem hiding this comment.
Good start, person class init looks complete but relationships needs more work (and an example at bottom)
group.py
Outdated
|
|
||
|
|
||
|
|
||
| Jill_relations = {Zalika: ""friend", John: "partner"} |
There was a problem hiding this comment.
I think there's an unclosed quote here
| Jill_relations = {Zalika: ""friend", John: "partner"} | |
| Jill_relations = {Zalika: "friend", John: "partner"} |
stefpiatek
left a comment
There was a problem hiding this comment.
Nice work, added in a suggestion and a challenge for using comprehensions that filter based on conditions for the last two questions
|
|
||
| #1. The maximum age of people in the group | ||
|
|
||
| max_age = max([group[person]["age"] for person in group]) |
There was a problem hiding this comment.
You can also iterate just through the values in a dictionary
| max_age = max([group[person]["age"] for person in group]) | |
| max_age = max([person["age"] for person in group.values()]) |
|
|
||
| #2. The mean number of relationships for people in the group | ||
|
|
||
| import numpy as np |
There was a problem hiding this comment.
FYI, import statements should be at the top of the file
| group_w_rels = { } #create a new group for people with relations | ||
|
|
||
|
|
||
| for person in group: | ||
| if len(group[person]["relations"]) > 0: | ||
| group_w_rels[person] = group[person] | ||
|
|
||
| #max age of person in group of people with relations | ||
| max_age_rels = max( | ||
| group_w_rels[person]["age"] for person in group_w_rels | ||
| ) |
There was a problem hiding this comment.
Can you do all of this with one list comprehension? You can add an if statement to the right hand side of a comprehension for filtering
Class-based draft approach (work-in-progress)
@thandi1908 @Jiayi21 @ myx2021 @JiefuMei @SolemnShark871
#Answers UCL-MPHY0021-21-22/RSE-Classwork#7