Skip to content

Arosi solo attempt#23

Open
AbsArosi wants to merge 7 commits intoUCL-MPHY0021-21-22:mainfrom
AbsArosi:ArosiGroupAttempt
Open

Arosi solo attempt#23
AbsArosi wants to merge 7 commits intoUCL-MPHY0021-21-22:mainfrom
AbsArosi:ArosiGroupAttempt

Conversation

@AbsArosi
Copy link

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

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, some feedback for a bit of style and simplifying comprehension expressions

Comment on lines +24 to +28
"NewGuyNoFriends": {
"age": 150,
"job": "student",
"relations": {
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

poor guy 😢

}

# the maximum age of people in the group
max_age = max([group.get(personName).get("age") for personName in group.keys()])
Copy link
Collaborator

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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")])

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