Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class_3-checkpoint.ipynb
96 changes: 96 additions & 0 deletions class_3.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "f21f00a0",
"metadata": {},
"source": [
"# Friend group mapping"
]
},
{
"cell_type": "code",
"execution_count": 51,
"id": "c6e8b4ae",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting group.py\n"
]
}
],
"source": [
"%%writefile group.py\n",
"group = {\n",
" \"Jill\": {\n",
" \"age\": 26,\n",
" \"job\": \"biologist\",\n",
" \"relations\": {\n",
" \"Zalika\": \"friend\",\n",
" \"John\": \"partner\"\n",
" }\n",
" },\n",
" \"Zalika\": {\n",
" \"age\": 28,\n",
" \"job\": \"artist\",\n",
" \"relations\": {\n",
" \"Jill\": \"friend\"\n",
" }\n",
" },\n",
" \"John\": {\n",
" \"age\": 27,\n",
" \"job\": \"writer\",\n",
" \"relations\": {\n",
" \"Jill\": \"partner\"\n",
" }\n",
" },\n",
" \"Nash\": {\n",
" \"age\": 34,\n",
" \"job\": \"chef\",\n",
" \"relations\": {\n",
" \"John\": \"cousin\",\n",
" \"Zalika\": \"landlord\"\n",
" }\n",
" }\n",
"}\n",
"# the maximum age of people in the group\n",
"print(\"the maximum age of people in the group is \", \n",
" max([attr[\"age\"] for person, attr in group.items()]))\n",
"# the average (mean) number of relations among members of the group\n",
"relat = [len(attr[\"relations\"]) for person, attr in group.items()]\n",
"print(\"the average (mean) number of relations among members of the group is \", \n",
" sum(relat) / len(relat))\n",
"# the maximum age of people in the group that have at least one relation\n",
"print(\"the maximum age of people in the group that have at least one relation is \",\n",
" max([attr[\"age\"] for person, attr in group.items() if len(attr[\"relations\"]) >=1]))\n",
"# [more advanced] the maximum age of people in the group that have at least one friend\n",
"print(\"the maximum age of people in the group that have at least one friend is \",\n",
" max([attr[\"age\"] for person, attr in group.items() if \"friend\" in attr[\"relations\"].values()]))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
50 changes: 45 additions & 5 deletions group.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
"""An example of how to represent a group of acquaintances in Python."""

# Your code to go here...

my_group =
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"
}
}
}
# the maximum age of people in the group
print("the maximum age of people in the group is ",
max([attr["age"] for person, attr in group.items()]))
# the average (mean) number of relations among members of the group
relat = [len(attr["relations"]) for person, attr in group.items()]
print("the average (mean) number of relations among members of the group is ",
sum(relat) / len(relat))
# the maximum age of people in the group that have at least one relation
print("the maximum age of people in the group that have at least one relation is ",
max([attr["age"] for person, attr in group.items() if len(attr["relations"]) >=1]))
# [more advanced] the maximum age of people in the group that have at least one friend
print("the maximum age of people in the group that have at least one friend is ",
max([attr["age"] for person, attr in group.items() if "friend" in attr["relations"].values()]))