好吧,我正在尝试创建一个函数来更新/创建两个字典来包含来自打开文件的数据。在
示例文本文件如下所示:Dunphy, Claire # Name of the person
Parent Teacher Association # The networks person is associated with
Dunphy, Phil # List of friends
Pritchett, Mitchell
Pritchett, Jay
Dunphy, Phil
Real Estate Association
Dunphy, Claire
Dunphy, Luke
Pritchett, Jay
Pritchett, Gloria
Delgado, Manny
Dunphy, Claire
def load_profiles(profiles_file, person_to_friends, person_to_networks):假设profiles_文件已全部打开,因此不需要传递参数来打开文件
person-to-friend是一个字典,每个键都是一个person(str),每个值是这个人的朋友(str列表)。
人与网络是一个字典,每个键都是一个人(str),每个值是人所属的网络(str列表)。
所以我想把这个问题分成子函数/helper函数会更容易,一个函数创建person-to-friend字典,另一个创建person-to-network字典。在
到目前为止,我提出了一个“人与朋友”的功能:
^{pr2}$
但这是退回一本空字典,不知道我做错了什么。也不知道如何添加朋友作为人的价值观。在