Skip to content

Adding function for gathering information about age and number of relations #55

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion group.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,32 @@

# Your code to go here...

my_group =
my_group = {"Jill":
Copy link

Choose a reason for hiding this comment

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

did you run the formatter here? (ruff)

{"Job":"Biologist", "Age":"26", "Relations":[("Zalika","Friend"),("John","Partner")]},
"Zalika":
{"Job":"Artist", "Age":"28", "Relations":[("Jill","Friend")]},
"John":
{"Job":"Writer", "Age":"27", "Relations":[("Zalika","Partner")]},
"Nash":
{"Job":"Chef", "Age":"34", "Relations":[("John","Cousin"),("Zalika","Landlord")]}}


def age_relation_info(group=my_group):
age_vec = []
age_relat_vec = []
age_friend_vec = []
relation_vec = []
for key in group:
age_vec.append(int(group[key]["Age"]))
if group[key]["Relations"]:
relation_vec.append(len(group[key]["Relations"]))
age_relat_vec.append(int(group[key]["Age"]))
for relation in group[key]["Relations"]:
if "Friend" in relation:
age_friend_vec.append(int(group[key]["Age"]))

return(
f"Max Age: {max(age_vec)}; Average Relations: {sum(relation_vec)/len(group)}; Max Age with >=1 Relation: {max(age_relat_vec)}; Max Age with >=1 Friend: {max(age_friend_vec)}"
)

age_relation_info()
Copy link

Choose a reason for hiding this comment

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

this will run every time you import group.py

wrap in a if name == "main" condition :-)