From aabf5fd4410081a2f9356658f317a045a49f032f Mon Sep 17 00:00:00 2001 From: Lingwen Date: Mon, 24 Oct 2022 00:34:58 +0100 Subject: [PATCH] Design a data structure --- group.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/group.py b/group.py index e2ec347..8ea59ab 100644 --- a/group.py +++ b/group.py @@ -2,4 +2,23 @@ # Your code to go here... -my_group = +import collections +class person: + + def __init__(self, name, age, job) -> None: + self.name = name + self.age = age + self.job = job + self.connection = collections.defaultdict(list) + + def add_connection(self, friend): + self.connection[self.name].append(friend) + +Jill = person('Jill', 27, 'writer') +Jill.add_connection("zalika") +Jill.add_connection('Dave') + +Zalika = person('Zalika', 28, 'artist') +Dave = person('Dave', 34, 'driver') + +print(Jill.connection)