Skip to content

data structure to represent a group of acquaintances using dictionaries and lists #56

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
44 changes: 43 additions & 1 deletion group.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,46 @@

# Your code to go here...

my_group =
my_group = [
{
"Name": "Jill",
"Age": 26,
"Job": "Biologist",
"Connections": {"Zalika": "friend",
"John": "partner"}
},
{
"Name": "Zalika",
"Age": 28,
"Job": "Artist",
"Connections": {"Jill": "friend",
"Nash": "landlord"}
},
{
"Name": "John",
"Age": 27,
"Job": "Writer",
"Connections": {"Jill": "partner"}
},
{
"Name": "Nash",
"Age": 34,
"Job": "Chef",
"Connections": {"John": "cousin",
"Zalika": "tennant"}
}
]

import numpy as np

max_age = max(person["Age"] for person in my_group)
print(f"Maximum age: {max_age}")

avg_nb_relations = np.mean([len(person["Connections"]) for person in my_group])
print(f"Average number of relations: {avg_nb_relations}")

max_age_with_at_least_one_relation = max(person["Age"] for person in my_group if len(person["Connections"]) >= 1)
print(f"Maximum age of people who have at least one relation: {max_age_with_at_least_one_relation}")

max_age_with_at_least_one_friend = max(person["Age"] for person in my_group if sum(relation=="friend" for relation in person["Connections"].values()) >= 1)
print(f"Maximum age of people who have at least one friend {max_age_with_at_least_one_friend}")