From 133021362ca35a10921321722b4d4c0615e169ea Mon Sep 17 00:00:00 2001 From: Danqing-Huang Date: Thu, 29 Oct 2020 06:57:09 +0000 Subject: [PATCH] add to json file --- group.py | 45 ++++++++++++++++++++++++++++++++++++++++++--- group_friends.json | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 group_friends.json diff --git a/group.py b/group.py index e2ec347..46a0740 100644 --- a/group.py +++ b/group.py @@ -1,5 +1,44 @@ -"""An example of how to represent a group of acquaintances in Python.""" +import json -# Your code to go here... +group = { + "Jill": { + "age": 26, + "job": "biologist", + "relations": { + "Zalika": "friend", + "John": "partner" + } + }, + "Zalika": { + "age": 28, + "job": "artist", + "relations": { + "Jill": "friend" + } + }, + "John": { + "age": 27, + "job": "writer", + "relations": { + "Jill": "partner" + } + }, + "Nash": { + "age": 34, + "job": "chef", + "relations": { + "John": "cousin", + "Zalika": "landlord" + } + } +} -my_group = +# write file +with open('group_friends.json', 'w') as json_file: + json.dump(group, json_file, indent=4) + + +with open('group_friends.json', 'r') as json_file: + group_friends = json_file.read() + +print(group_friends) diff --git a/group_friends.json b/group_friends.json new file mode 100644 index 0000000..43462ec --- /dev/null +++ b/group_friends.json @@ -0,0 +1,32 @@ +{ + "Jill": { + "age": 26, + "job": "biologist", + "relations": { + "Zalika": "friend", + "John": "partner" + } + }, + "Zalika": { + "age": 28, + "job": "artist", + "relations": { + "Jill": "friend" + } + }, + "John": { + "age": 27, + "job": "writer", + "relations": { + "Jill": "partner" + } + }, + "Nash": { + "age": 34, + "job": "chef", + "relations": { + "John": "cousin", + "Zalika": "landlord" + } + } +} \ No newline at end of file