Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.
Open
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
36 changes: 19 additions & 17 deletions 01-beginner/029structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Nested Lists and Dictionaries"
"## Nested lists and dictionaries"
]
},
{
Expand All @@ -28,9 +28,11 @@
"metadata": {},
"outputs": [],
"source": [
"UCL = {'City': 'London', \n",
" 'Street': 'Gower Street',\n",
" 'Postcode': 'WC1E 6BT'}"
"ucl_address = {\n",
" 'City': 'London', \n",
" 'Street': 'Gower Street',\n",
" 'Postcode': 'WC1E 6BT'\n",
"}"
]
},
{
Expand All @@ -39,7 +41,7 @@
"metadata": {},
"outputs": [],
"source": [
"MyHouse = {\n",
"house_address = {\n",
" 'City': 'London',\n",
" 'Street': 'Waterson Street',\n",
" 'Postcode': 'E2 8HH'\n",
Expand All @@ -59,7 +61,7 @@
"metadata": {},
"outputs": [],
"source": [
"addresses = [UCL, MyHouse]"
"addresses = [ucl_address, house_address]"
]
},
{
Expand All @@ -84,7 +86,7 @@
"metadata": {},
"outputs": [],
"source": [
"UCL[\"People\"] = [\"Clare\", \"James\", \"Owain\"]"
"ucl_address[\"People\"] = [\"Clare\", \"James\", \"Owain\"]"
]
},
{
Expand All @@ -93,7 +95,7 @@
"metadata": {},
"outputs": [],
"source": [
"MyHouse[\"People\"] = [\"Sue\", \"James\"]"
"house_address[\"People\"] = [\"Sue\", \"James\"]"
]
},
{
Expand All @@ -116,7 +118,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"We can go further, e.g.:"
"We can go further, for example:"
]
},
{
Expand All @@ -125,7 +127,7 @@
"metadata": {},
"outputs": [],
"source": [
"UCL[\"Residential\"] = False"
"ucl_address[\"Residential\"] = False"
]
},
{
Expand All @@ -141,29 +143,29 @@
"metadata": {},
"outputs": [],
"source": [
"leaders = [place[\"People\"][0] for place in addresses]\n",
"print(leaders)"
"total_number_of_people = sum([len(place[\"People\"]) for place in addresses])\n",
"print(total_number_of_people)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This was an example of a 'list comprehension', which is used to get data of this structure, and which we'll see more of in a moment..."
"The syntax inside the square brackets `[]` in the [`sum` function](https://docs.python.org/3/library/functions.html#sum) is an example of a _list comprehension_ - we'll learn more about these in a later notebook."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercise: a Maze Model."
"## Exercise: a maze model."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Work with a partner to design a data structure to represent a maze using dictionaries and lists."
"Design a data structure to represent a maze using dictionaries and lists."
]
},
{
Expand Down Expand Up @@ -261,9 +263,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.1"
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}