From 92e66d26174ebfa6a1cfa4ae818ff18bafe40fe4 Mon Sep 17 00:00:00 2001 From: wangxinping Date: Mon, 14 Oct 2024 10:21:38 +0100 Subject: [PATCH 1/6] add personal information --- group.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/group.py b/group.py index e2ec347..f54f022 100644 --- a/group.py +++ b/group.py @@ -2,4 +2,14 @@ # Your code to go here... -my_group = +my_group =[{ "name": "Luhan", "age": 22, "job": "Student"}, + { "name": "Wangjiayi", "age": 22, "job": "Student"}, + {"name": "Wangxinping", "age": 22, "job": "Student"}] + + + + +for row in my_group: + print(f"{row['name']} is {row['age']}, a {row['job']}.") + + From bb245282933e55209e1ff8eafdc0dab8a2dd6d9e Mon Sep 17 00:00:00 2001 From: Chloe Wang Date: Mon, 14 Oct 2024 11:03:51 +0100 Subject: [PATCH 2/6] hi --- group.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/group.py b/group.py index f54f022..b080a93 100644 --- a/group.py +++ b/group.py @@ -8,7 +8,7 @@ - +--- for row in my_group: print(f"{row['name']} is {row['age']}, a {row['job']}.") From a2a7564e161c944d83a5c6c65962b758f19e8b66 Mon Sep 17 00:00:00 2001 From: Chloe Wang Date: Mon, 14 Oct 2024 11:13:29 +0100 Subject: [PATCH 3/6] new --- group.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/group.py b/group.py index b080a93..d28376c 100644 --- a/group.py +++ b/group.py @@ -8,7 +8,7 @@ ---- +hh for row in my_group: print(f"{row['name']} is {row['age']}, a {row['job']}.") From a0feba7e822236fe68d89ab36bead5972fe17c8d Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 16 Oct 2024 16:02:49 +0100 Subject: [PATCH 4/6] update the group info --- group.py | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/group.py b/group.py index d28376c..0222f6f 100644 --- a/group.py +++ b/group.py @@ -2,14 +2,48 @@ # Your code to go here... -my_group =[{ "name": "Luhan", "age": 22, "job": "Student"}, - { "name": "Wangjiayi", "age": 22, "job": "Student"}, - {"name": "Wangxinping", "age": 22, "job": "Student"}] +my_group = [ + { + 'name': 'Jill', + 'age': 26, + 'job':'a biologist', + 'connection': { + 'friend': ['Zalika'], + 'partner': ['John'] + } + }, + { + 'name': 'Zalika', + 'age': 28, + 'job':'an artist', + 'connection': { + 'friend' : ['Jill'] + } + }, + { + 'name': 'John', + 'age': 27, + 'job':'a writer', + 'connection': { + 'partner' : ['Jill'] + } + }, + { + 'name': 'Nash', + 'age': 34, + 'job':'a chef', + 'connection': { + 'cousin' : ['John'], + 'landlord' : ['Zalika'] + } + } +] - -hh for row in my_group: - print(f"{row['name']} is {row['age']}, a {row['job']}.") + connections = " and ".join([f"{v[0]}'s {k}" for k, v in row['connection'].items()]) + print(f"{row['name']} is {row['age']}, {row['job']}, {connections}") + + From 6436ef27bc4caaa9548fc9215ed91a8d631a0aa8 Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 16 Oct 2024 17:55:05 +0100 Subject: [PATCH 5/6] modify the print_my_group --- group.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/group.py b/group.py index 0222f6f..7a056d5 100644 --- a/group.py +++ b/group.py @@ -39,11 +39,15 @@ } ] - -for row in my_group: - connections = " and ".join([f"{v[0]}'s {k}" for k, v in row['connection'].items()]) - print(f"{row['name']} is {row['age']}, {row['job']}, {connections}") - +def print_my_group(): + for row in my_group: + connections = " and ".join([f"{', '.join(map(str, v))}'s {k}" for k, v in row["connection"].items() if v]) + print(f"{row['name']} is {row['age']}, {row['job']}, {connections}") + print("\n") +# the maximum age of people in the group +# the average (mean) number of relations among members of the group +# the maximum age of people in the group that have at least one relation +# [more advanced] the maximum age of people in the group that have at least one friend From 05912d309960a6dc55029834ee2fcb100dc19f2a Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 16 Oct 2024 18:09:17 +0100 Subject: [PATCH 6/6] summary data from group --- group.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/group.py b/group.py index 7a056d5..42d90d9 100644 --- a/group.py +++ b/group.py @@ -48,6 +48,18 @@ def print_my_group(): # the maximum age of people in the group +max_age = max([v['age'] for v in my_group]) +print(f'the maximum age of people in the group is {max_age}') + # the average (mean) number of relations among members of the group +relations_count = [len(person['connection']) for person in my_group] +avg_relations = sum(relations_count) / len(relations_count) +print(f'The average (mean) number of relations among members of the group is {avg_relations:.2f}') + # the maximum age of people in the group that have at least one relation +_max_age = max([v['age'] for v in my_group if len(v['connection']) > 0]) +print(f'the maximum age of people in the group that have at least one relation is {_max_age}') + # [more advanced] the maximum age of people in the group that have at least one friend +_max_age_ = max([v['age'] for v in my_group if 'friend' in v['connection'] and v['connection']['friend']]) +print(f'the maximum age of people in the group that have at least one friend is {_max_age_}') \ No newline at end of file