From 85a811939cf4657deed1cbd40e49071725299956 Mon Sep 17 00:00:00 2001 From: Victor Baycroft Date: Mon, 14 Oct 2024 10:38:28 +0100 Subject: [PATCH 1/2] Creating a group of friends --- group.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/group.py b/group.py index e2ec347..2a2daf2 100644 --- a/group.py +++ b/group.py @@ -2,4 +2,13 @@ # Your code to go here... -my_group = +my_group = {"Jill": + {"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")]}} + +print(my_group["Jill"]["Relations"][0]) \ No newline at end of file From f1f18cd2450615a9976eb8c697f316115646ab25 Mon Sep 17 00:00:00 2001 From: cansuoktem Date: Mon, 14 Oct 2024 14:20:09 +0100 Subject: [PATCH 2/2] Adding new function for age and relations --- group.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/group.py b/group.py index 2a2daf2..da47d43 100644 --- a/group.py +++ b/group.py @@ -3,7 +3,7 @@ # Your code to go here... my_group = {"Jill": - {"Job":"Biologist", "Age":"26", "Relations":[("Zalika","Friend"),("John","partner")]}, + {"Job":"Biologist", "Age":"26", "Relations":[("Zalika","Friend"),("John","Partner")]}, "Zalika": {"Job":"Artist", "Age":"28", "Relations":[("Jill","Friend")]}, "John": @@ -11,4 +11,23 @@ "Nash": {"Job":"Chef", "Age":"34", "Relations":[("John","Cousin"),("Zalika","Landlord")]}} -print(my_group["Jill"]["Relations"][0]) \ No newline at end of file + +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()