From 94db88116d416b784796b422d2bcf2d333ced3e9 Mon Sep 17 00:00:00 2001 From: Weixuan Xing Date: Sun, 30 Oct 2022 16:50:53 +0000 Subject: [PATCH 1/2] groupset --- group.py | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/group.py b/group.py index e2ec347..59e188b 100644 --- a/group.py +++ b/group.py @@ -2,4 +2,37 @@ # Your code to go here... -my_group = +my_group = { + "Jack":{ + "age":25, + "job": "history teacher", + "relations":{ + "Sam": "friend", + "Alex":"partner", + "Zoe": "brother" + } + }, + "Sam":{ + "age":27, + "job": "bartender", + "relations":{ + "Jack": "friend", + "Alex": "friend" + } + }, + "Zeo":{ + "age":19, + "job": "student", + "relations":{ + "Jack": "sister", + } + }, + "Alex":{ + "age":22, + "job": "archeologist", + "relations":{ + "Jack": "partner", + "Alex": "friend" + } + } +} From bbac95030138a6e69e98c24ede6430ac834e61e9 Mon Sep 17 00:00:00 2001 From: Weixuan Xing Date: Sun, 30 Oct 2022 18:15:29 +0000 Subject: [PATCH 2/2] dispay of info in dictionary --- group.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/group.py b/group.py index 59e188b..833709d 100644 --- a/group.py +++ b/group.py @@ -29,10 +29,24 @@ }, "Alex":{ "age":22, - "job": "archeologist", + "job": "archeologist", "relations":{ - "Jack": "partner", - "Alex": "friend" + #"Jack": "partner", + #"Alex": "friend" } } } + +agelist = [] +joblist = [] +relation = [] +for name, detail in my_group.items(): + agelist += [detail["age"]] + joblist += [detail["job"]] + relation += [detail["relations"]] +print(agelist)# print the age, job and relation of people +print(joblist)#But this presentation does not allows people with no key of job or relatoion +print(relation)#It can present the empty key of job and relation +#ages = [properties["age"] for properties in my_group.values()] ---another way +age_of_people_with_many_friends = [properties["age"] for properties in my_group.values() if len(properties["relations"])>=3] +print(age_of_people_with_many_friends)