Skip to content

Class based unfinished approach#14

Open
SolemnShark871 wants to merge 4 commits intoUCL-MPHY0021-21-22:mainfrom
SolemnShark871:Jiayi21-JiefuMei-myx2021-thandi1908-SolemnShark871
Open

Class based unfinished approach#14
SolemnShark871 wants to merge 4 commits intoUCL-MPHY0021-21-22:mainfrom
SolemnShark871:Jiayi21-JiefuMei-myx2021-thandi1908-SolemnShark871

Conversation

@SolemnShark871
Copy link

Class-based draft approach (work-in-progress)

@thandi1908 @Jiayi21 @ myx2021 @JiefuMei @SolemnShark871

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

@@ -2,4 +2,20 @@

# Your code to go here...
Copy link

Choose a reason for hiding this comment

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

Good start, person class init looks complete but relationships needs more work (and an example at bottom)

Copy link

@JakeVoon JakeVoon left a comment

Choose a reason for hiding this comment

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

Nice idea using classes!

group.py Outdated



Jill_relations = {Zalika: ""friend", John: "partner"}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think there's an unclosed quote here

Suggested change
Jill_relations = {Zalika: ""friend", John: "partner"}
Jill_relations = {Zalika: "friend", John: "partner"}

Copy link
Collaborator

@stefpiatek stefpiatek left a comment

Choose a reason for hiding this comment

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

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])
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can also iterate just through the values in a dictionary

Suggested change
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
Copy link
Collaborator

Choose a reason for hiding this comment

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

FYI, import statements should be at the top of the file

Comment on lines +80 to +90
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
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

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

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.

4 participants