Skip to content
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
59 changes: 58 additions & 1 deletion group.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,61 @@

# Your code to go here...

my_group =
connections = ["friend", "partner", "landlord", "cousin", "tenant"]
my_group = {
"Jill": {
"age": 26,
"job": "biologist",
"connections": {"Zalika": connections[0], "John": connections[1]},
},
"Zalika": {
"age": 28,
"job": "artist",
"connections": {"Jill": connections[0], "Nash": connections[4]},
},
"John": {
"age": 27,
"job": "writer",
"connections": {"Jill": connections[1], "Nash": connections[3]},
},
"Nash": {
"age": 34,
"job": "chef",
"connections": {"Zalika": connections[2], "John": connections[3]},
},
}


import numpy as np
#The maximum age of people in the group.
max_age = max(person['age'] for person in my_group.values())
print(f"maximum age: {max_age}")

#The average number of relations each person has.
mean_relations = np.mean([len(person['connections']) for person in my_group.values()])
print(f"average number of relations: {int(mean_relations)}")

# Finding the maximum age of people who have at least one relation
max_age_with_ge_one_relation = max(person['age'] for person in my_group.values() if person['connections'])
print(f"maximum age of people who have at least one relation: {max_age_with_ge_one_relation}")

# Finding the maximum age of people who have at least one friend
max_age_with_ge_one_friend = max([person['age'] for person in my_group.values() if list(person['connections'].values()).count("friend")>=1])
print(f"maximum age of people who have at least one friend {max_age_with_ge_one_friend}")

def forget(person1, person2):
if person1 in my_group and person2 in my_group[person1]['connections']:
del my_group[person1]['connections'][person2]

if person2 in my_group and person1 in my_group[person2]['connections']:
del my_group[person2]['connections'][person1]

def add_person(name, age, job, relations):
my_group[name] = {
"age": age,
"job": job,
"connections": relations
}

def average_age():
return np.mean([person['age'] for person in my_group.values()])