-
Notifications
You must be signed in to change notification settings - Fork 52
Arosi solo attempt #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c99f39b
1693e9a
4147b14
5575a52
250e646
52b8139
e4aa316
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,5 +1,60 @@ | ||||||
| """An example of how to represent a group of acquaintances in Python.""" | ||||||
| group = { | ||||||
| "Jill": { | ||||||
| "age": 26, | ||||||
| "job": "biologist", | ||||||
| "relations": { | ||||||
| "Zalika": "friend", | ||||||
| "John": "partner" | ||||||
| } | ||||||
| }, | ||||||
| "Zalika": { | ||||||
| "age": 28, | ||||||
| "job": "artist", | ||||||
| "relations": { | ||||||
| "Jill": "friend" | ||||||
| } | ||||||
| }, | ||||||
| "John": { | ||||||
| "age": 27, | ||||||
| "job": "writer", | ||||||
| "relations": { | ||||||
| "Jill": "partner" | ||||||
| } | ||||||
| }, | ||||||
| "NewGuyNoFriends": { | ||||||
| "age": 150, | ||||||
| "job": "student", | ||||||
| "relations": { | ||||||
| } | ||||||
| }, | ||||||
| "Nash": { | ||||||
| "age": 34, | ||||||
| "job": "chef", | ||||||
| "relations": { | ||||||
| "John": "cousin", | ||||||
| "Zalika": "landlord" | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| # 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. Choose a reason for hiding this commentThe 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
|
||||||
| 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. Choose a reason for hiding this commentThe 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 |
||||||
| relationships_dict_list = [group.get(personName).get("relations") for personName in group.keys()] | ||||||
| mean_relations = np.mean([len(personalRelations.keys()) for personalRelations in relationships_dict_list]) | ||||||
| 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could also use the inherent "falsyness" of an empty dictionary
Suggested change
|
||||||
| print("oldest person with at least one relation of any type is", max_non_relationless, "years old") | ||||||
|
|
||||||
| # [more advanced] the maximum age of people in the group that have at least one friend | ||||||
| max_nonfriendless = max([group.get(personName).get("age") for personName in group.keys() if "friend" in list(group.get(personName).get("relations").values())]) | ||||||
| print("oldest person with a relation of type friend is", max_nonfriendless, "years old") | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
| # Your code to go here... | ||||||
|
|
||||||
| my_group = | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
poor guy 😢