Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 52 additions & 3 deletions group.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,54 @@
"""An example of how to represent a group of acquaintances in Python."""
# Using the example code from the lecture

# 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 =
def mean(data):
"""Compute the mean of a non-empty list of numbers."""
return sum(data) / len(data)


print(max(person["age"] for person in group.values()))
print(mean([len(person["relations"]) for person in group.values()]))
print(max(person["age"] for person in group.values() if person["relations"]))
print(max(person["age"] for person in group.values() if "friend" in person["relations"].values()))

import json

#write file
with open('group_file.json', 'w') as json_file:
json.dumps(group, json_file, indent=4)

#read file
with open('group_file.json', 'r') as json_file:
group_data = json_file.read()
Empty file added group_file.json
Empty file.