From 1cd38369c11411273f3c89cb8925eb6264ed2e20 Mon Sep 17 00:00:00 2001
From: Auke Klazema <klazema@astron.nl>
Date: Wed, 17 Nov 2021 17:38:24 +0100
Subject: [PATCH] Fleshed out the data types

---
 IntroProgrammingInPython.ipynb | 1112 +++++++++++++++++++++++++++++++-
 1 file changed, 1091 insertions(+), 21 deletions(-)

diff --git a/IntroProgrammingInPython.ipynb b/IntroProgrammingInPython.ipynb
index 9475803..9467482 100644
--- a/IntroProgrammingInPython.ipynb
+++ b/IntroProgrammingInPython.ipynb
@@ -841,12 +841,277 @@
    "id": "41925997-1b78-44a5-a336-ae9a2c87960c",
    "metadata": {},
    "source": [
-    "## Variables"
+    "## Variables\n",
+    "\n",
+    "A variable is a name or pointer to a value. To create a variable we can pick a name and assign it a value with the '=' character like so:"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 218,
+   "id": "ec429a84-de01-40bf-8bc6-67aaea81d240",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "1\n"
+     ]
+    }
+   ],
+   "source": [
+    "name = 1\n",
+    "print(name)"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "b57b1f6f-8ffd-4941-ad11-4a488adeba80",
+   "metadata": {},
+   "source": [
+    "We cant pick any name for a variable. A variable needs to start with letter or an underscore. The remainder of the variable name can only be alpha-numeric characters or underscores."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 222,
+   "id": "7734e532-9edd-4013-a838-6ecfe32dcb85",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "_hello = 1\n",
+    "hello = 1\n",
+    "hello2 = 1\n",
+    "hello_3 = 1\n",
+    "Hello_A = 1"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 226,
+   "id": "85cfaf9b-5309-4ac7-8fd9-2034e4adb4f9",
+   "metadata": {},
+   "outputs": [
+    {
+     "ename": "SyntaxError",
+     "evalue": "invalid decimal literal (<ipython-input-226-ac1344e44015>, line 1)",
+     "output_type": "error",
+     "traceback": [
+      "\u001b[0;36m  File \u001b[0;32m\"<ipython-input-226-ac1344e44015>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m    1_value = 1\u001b[0m\n\u001b[0m     ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid decimal literal\n"
+     ]
+    }
+   ],
+   "source": [
+    "1_value = 1"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 228,
+   "id": "d379fb9d-30a3-4505-b98c-d5a77c0b500c",
+   "metadata": {},
+   "outputs": [
+    {
+     "ename": "SyntaxError",
+     "evalue": "invalid syntax (<ipython-input-228-336cc308e9ba>, line 1)",
+     "output_type": "error",
+     "traceback": [
+      "\u001b[0;36m  File \u001b[0;32m\"<ipython-input-228-336cc308e9ba>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m    @tor = 1\u001b[0m\n\u001b[0m         ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
+     ]
+    }
+   ],
+   "source": [
+    "@tor = 1"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 230,
+   "id": "d9ec65ab-937c-4943-9b10-f923d4ee0363",
+   "metadata": {},
+   "outputs": [
+    {
+     "ename": "SyntaxError",
+     "evalue": "invalid syntax (<ipython-input-230-49ff6b8b9baa>, line 1)",
+     "output_type": "error",
+     "traceback": [
+      "\u001b[0;36m  File \u001b[0;32m\"<ipython-input-230-49ff6b8b9baa>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m    .der = 1\u001b[0m\n\u001b[0m    ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
+     ]
+    }
+   ],
+   "source": [
+    ".der = 1"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "86e1659b-dbdb-4873-82d0-bea56b9a29ec",
+   "metadata": {},
+   "source": [
+    "There are also reserved words we can't use.\n",
+    "\n",
+    "| Reserved | Reserved | Reserved | Reserved | Reserved |\n",
+    "| ---       | ---       | ---       | ---       | ---    |\n",
+    "| False     | await     | else      | import    | pass   |\n",
+    "| None      | break     | except    | in        | raise  |\n",
+    "| True      | class     | finally   | is        | return |\n",
+    "| and       | continue  | for       | lambda    | try    |\n",
+    "| as        | def       | from      | nonlocal  | while  |\n",
+    "| assert    | del       | global    | not       | with   |\n",
+    "| async     | elif      | if        | or        | yield  |"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 233,
+   "id": "fc0f7f9b-440b-4d16-bc12-24fafd18a112",
+   "metadata": {},
+   "outputs": [
+    {
+     "ename": "SyntaxError",
+     "evalue": "cannot assign to None (<ipython-input-233-d03f602a0186>, line 1)",
+     "output_type": "error",
+     "traceback": [
+      "\u001b[0;36m  File \u001b[0;32m\"<ipython-input-233-d03f602a0186>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m    None = 1\u001b[0m\n\u001b[0m    ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m cannot assign to None\n"
+     ]
+    }
+   ],
+   "source": [
+    "None = 1"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 235,
+   "id": "7d460e27-69e1-4885-ba6c-b00ca6f233ca",
+   "metadata": {},
+   "outputs": [
+    {
+     "ename": "SyntaxError",
+     "evalue": "invalid syntax (<ipython-input-235-773eba7f7781>, line 1)",
+     "output_type": "error",
+     "traceback": [
+      "\u001b[0;36m  File \u001b[0;32m\"<ipython-input-235-773eba7f7781>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m    if = 1\u001b[0m\n\u001b[0m       ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
+     ]
+    }
+   ],
+   "source": [
+    "if = 1"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 238,
+   "id": "5ca05cdd-9fb6-49af-a5b4-6bd0cea82309",
+   "metadata": {},
+   "outputs": [
+    {
+     "ename": "SyntaxError",
+     "evalue": "invalid syntax (<ipython-input-238-fca67dd73332>, line 1)",
+     "output_type": "error",
+     "traceback": [
+      "\u001b[0;36m  File \u001b[0;32m\"<ipython-input-238-fca67dd73332>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m    with = 1\u001b[0m\n\u001b[0m         ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
+     ]
+    }
+   ],
+   "source": [
+    "with = 1"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "e9a4844c-e536-45ce-bc87-c572204c2ad2",
+   "metadata": {},
+   "source": [
+    "And variables as case sensitive."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 239,
+   "id": "6d88c116-5e8e-4623-9af7-4176f87ad7a5",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "1\n",
+      "2\n"
+     ]
+    }
+   ],
+   "source": [
+    "a = 1\n",
+    "A = 2\n",
+    "print(a)\n",
+    "print(A)"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "7b845940-7289-4373-aa50-3dc0887d8b7a",
+   "metadata": {},
+   "source": [
+    "The general coding style used by the Python developers is written down in pep8. It also has something to say about variable names:\n",
+    "\n",
+    "> Variable names should be lowercase, with words separated by underscores as necessary to improve readability."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 241,
+   "id": "9ab676b5-8fbd-43ae-acac-c1c76bb40954",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "total_amount = 22"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "9703da1e-d26e-4941-beb4-14b7cafc5e45",
+   "metadata": {},
+   "source": [
+    "We can change the value of the variable at all times. Even if the value is of a different type."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 242,
+   "id": "984dd4bf-8f79-4dda-9d86-f71f0f117cce",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "1\n",
+      "Hello\n"
+     ]
+    }
+   ],
+   "source": [
+    "value = 1\n",
+    "print(value)\n",
+    "value = \"Hello\"\n",
+    "print(value)"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "98e5daea-9135-49d8-9459-1b757590ab9c",
+   "metadata": {},
+   "source": [
+    "### Exercise\n",
+    "\n",
+    "Ask the user for two numbers and print the result of some math operation on those numbers. You can use the input() function to get the user input. See small example below. "
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 146,
+   "execution_count": 246,
    "id": "68528cd0-d4c1-4e86-93c1-f5e1d187fc84",
    "metadata": {},
    "outputs": [
@@ -861,13 +1126,13 @@
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "Auke\n"
+      "Hello Auke\n"
      ]
     }
    ],
    "source": [
     "user_input = input(\"What is your name?\")\n",
-    "print(user_input)"
+    "print(\"Hello\", user_input)"
    ]
   },
   {
@@ -875,7 +1140,9 @@
    "id": "65ae8a92-a9cd-4994-b443-0a987cf12c36",
    "metadata": {},
    "source": [
-    "### Scope"
+    "### Scope\n",
+    "\n",
+    "The scope where a variable can be used is limited to the block its defined in. A block can be the global block or a function block or a loop block. The search for the variable is always upword. So first the local block is searched and only if it can't be resolved there it will go up. We will come back to this concept later on."
    ]
   },
   {
@@ -1583,7 +1850,7 @@
    "id": "da426233-05e1-4b6c-a74d-d8e8221862d9",
    "metadata": {},
    "source": [
-    "### Excercise\n",
+    "### Exercise\n",
     "\n",
     "Get familiar with indexing and slices."
    ]
@@ -2049,28 +2316,830 @@
    "id": "7c011488-f5dc-4cea-85db-1fa202c2c240",
    "metadata": {},
    "source": [
-    "## Data types\n",
-    "### lists\n",
-    "### dictionaries\n",
-    "### sets\n",
-    "### tuples"
+    "## Compound data types\n",
+    "\n",
+    "So we have seen basic data types like numbers. And strings that are a chain of numbers intereted as characters. In the end we only have numbers in memory. But as programmers we can give meaning to these numbers and with it we can build complex data stuctures. We can use numbers to point to memory locations and that is what happens under the hood with the following compound data types."
    ]
   },
   {
    "cell_type": "markdown",
-   "id": "13e86fa7-c3ab-45fd-a1c0-876cc51c89c0",
+   "id": "71fb49a5-69d2-4cbc-9685-8fa8f8f7e7d2",
    "metadata": {},
    "source": [
-    "## Flow control\n",
-    "\n",
-    "In flow control we decide to run or skip certain code based on truth values. Python has the two object True and False reserved as truth values. The meaning of these objects is quite self explanetory.\n",
-    "\n",
-    "### If\n",
-    "\n",
-    "### While\n",
-    "\n",
-    "### For\n",
+    "### lists\n",
     "\n",
+    "Now we don't want to keep track of the meaning of all numbers so we abstract that away in programming languages. One nice abstractions is a grouping of things. We call that a list in many languages. Other languages sometimes call these arrays. So what does a list look like in Python?"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 179,
+   "id": "549f88c8-4087-4e97-98af-2983277b520a",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "[]"
+      ]
+     },
+     "execution_count": 179,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "# This is an empty list\n",
+    "[]"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 182,
+   "id": "a09f4e16-3843-44cd-8753-3b5bb92e7c3e",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "[1, 2, 3, 4, 5]"
+      ]
+     },
+     "execution_count": 182,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "# This is a list op numbers\n",
+    "[1, 2, 3, 4, 5]"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 184,
+   "id": "0e9582a6-7bb5-4215-b54c-968d059f6bf8",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "[1, 'Hello']"
+      ]
+     },
+     "execution_count": 184,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "# We can combine different types of data in a list\n",
+    "[1, \"Hello\"]"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "6c89200e-07b1-4398-b9e3-b2a37157098e",
+   "metadata": {},
+   "source": [
+    "Combining types is allowed, but for most algorithms that loop over a list it is required to have the items to be of the same type. What you see more often is that data of different types get added together in compound data type and those are then placed in a list. We will see some more examples of that later. "
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "3e955f00-a29c-4c3b-89d9-15acfc02d000",
+   "metadata": {},
+   "source": [
+    "We can ask the length of a list in the same manner as with strings with len()"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 210,
+   "id": "c516367b-1273-4528-a9e6-e8cda17c2365",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "2"
+      ]
+     },
+     "execution_count": 210,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "len([1, 2])"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "09da64e8-89b9-4213-8f11-9504a3ca1fd7",
+   "metadata": {},
+   "source": [
+    "Just with string we can also index and slice lists."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 187,
+   "id": "bca4829b-ac84-49c8-b027-e32bb01cda4c",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "1"
+      ]
+     },
+     "execution_count": 187,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "[1, 2, 3, 4, 5][0]"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 196,
+   "id": "9cd21b50-fcf2-4020-982a-bbbd345b5ad7",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "5"
+      ]
+     },
+     "execution_count": 196,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "[1, 2, 3, 4, 5][-1]"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 195,
+   "id": "f57bce1c-c387-4890-b807-6122868b2590",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "[2, 3, 4, 5]"
+      ]
+     },
+     "execution_count": 195,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "[1, 2, 3, 4, 5][1:]"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 198,
+   "id": "72090cf8-0114-45c0-a708-585d380eb891",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "[3, 4]"
+      ]
+     },
+     "execution_count": 198,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "[1, 2, 3, 4, 5][2:4]"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "eb0019c3-1316-42d8-b475-8cf2c0dec51a",
+   "metadata": {},
+   "source": [
+    "Also just like with strings we can create new lists by adding lists together."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 202,
+   "id": "b31d312f-3ca6-481b-8297-886c3dc9820f",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "[1, 2, 3, 4, 5]"
+      ]
+     },
+     "execution_count": 202,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "[1, 2, 3] + [4, 5]"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "df929be9-697d-4360-8f5b-70a6ca400518",
+   "metadata": {},
+   "source": [
+    "What we could not so with strings we can do with lists. We can alter the contents of the list."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 201,
+   "id": "84483bfd-ffbf-4d78-80d9-40169b9c9d52",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "[1, 2, 3]\n",
+      "[1, 2, 88]\n"
+     ]
+    }
+   ],
+   "source": [
+    "items = [1, 2, 3]\n",
+    "print(items)\n",
+    "items[2] = 88\n",
+    "print(items)"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "48708919-e711-4983-b44e-d4946da2c868",
+   "metadata": {},
+   "source": [
+    "We can append items to the list with .append()"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 203,
+   "id": "42a9c653-8e46-4293-b3f0-a96fe9e721a4",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "[]\n",
+      "[2]\n"
+     ]
+    }
+   ],
+   "source": [
+    "items = []\n",
+    "print(items)\n",
+    "items.append(2)\n",
+    "print(items)"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "bdd33cc2-9399-488e-b33d-399983b0a0a4",
+   "metadata": {},
+   "source": [
+    "We can also do fancy things with slices."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 209,
+   "id": "a350fa2d-6f81-4408-939d-9c6106cb591b",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "[1, 2, 3, 4, 5]\n",
+      "[1, 22, 33, 44, 5]\n",
+      "[1, 44, 5]\n"
+     ]
+    }
+   ],
+   "source": [
+    "items = [1, 2, 3, 4, 5]\n",
+    "print(items)\n",
+    "items[1:4] = [22, 33, 44]\n",
+    "print(items)\n",
+    "items[1:3] = []\n",
+    "print(items)"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "545fb3dd-f1ae-47b7-ae45-b9d231db20f4",
+   "metadata": {},
+   "source": [
+    "And we can also nest lists."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 216,
+   "id": "c242b92e-9531-4099-9fe1-392b6c37b26c",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "[[1, 2, 3], [4, 5]]\n",
+      "[1, 2, 3]\n",
+      "2\n"
+     ]
+    }
+   ],
+   "source": [
+    "items = [[1, 2, 3], [4, 5]]\n",
+    "print(items)\n",
+    "print(items[0])\n",
+    "print(items[0][1])"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "f3c07249-6b68-4d26-89b1-27ddcbd2517b",
+   "metadata": {},
+   "source": [
+    "#### Exercise\n",
+    "\n",
+    "Create some lists on your own. Add some together. Try some slices, indexing. Try to replace some items. Also think about a real world problem where lists could be useful."
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "d43526c9-a515-448d-96eb-16dc9b5e06fb",
+   "metadata": {},
+   "source": [
+    "### tuples\n",
+    "\n",
+    "A tuple is an immutable container. One can create a tuple with the parenthese characters '(' and ')'."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 248,
+   "id": "8bc04d51-abd6-45fb-bd72-d31e6b9adddd",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "()\n"
+     ]
+    }
+   ],
+   "source": [
+    "# This is a empty tuple\n",
+    "tup = ()\n",
+    "print(tup)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 250,
+   "id": "5f6468cd-7e3b-4c00-8790-931ec09d0eb1",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "(1,)\n"
+     ]
+    }
+   ],
+   "source": [
+    "# This is a single item tuple notice the ,\n",
+    "tup = (1,)\n",
+    "print(tup)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 252,
+   "id": "76e881a3-1aec-4baa-afdd-9fb131c42937",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "(1, 'Astron')\n"
+     ]
+    }
+   ],
+   "source": [
+    "# This is a tuple with multiple types\n",
+    "tup = (1, \"Astron\")\n",
+    "print(tup)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 255,
+   "id": "64952409-83b3-4b1a-a549-42ed695ca310",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "1"
+      ]
+     },
+     "execution_count": 255,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "# we can index a tuple\n",
+    "(1, \"Astron\")[0]"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 257,
+   "id": "25ef0a7b-982d-435b-a4da-59b35683e29b",
+   "metadata": {},
+   "outputs": [
+    {
+     "ename": "TypeError",
+     "evalue": "'tuple' object does not support item assignment",
+     "output_type": "error",
+     "traceback": [
+      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
+      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
+      "\u001b[0;32m<ipython-input-257-891212edf9e8>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;31m# We can't change a tuple once its created\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      2\u001b[0m \u001b[0mtup\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"Astron\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mtup\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
+      "\u001b[0;31mTypeError\u001b[0m: 'tuple' object does not support item assignment"
+     ]
+    }
+   ],
+   "source": [
+    "# We can't change a tuple once its created\n",
+    "tup = (1, \"Astron\")\n",
+    "tup[0] = 2"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 258,
+   "id": "3fb1ef09-cb58-4a52-bc33-d7217f7c70a8",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "4"
+      ]
+     },
+     "execution_count": 258,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "# We can also use len() on a tuple\n",
+    "len((1, 2, 3, \"Hello\"))"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "29f87318-a6a9-4d90-b352-6406720a9bf7",
+   "metadata": {},
+   "source": [
+    "We can also combine compound data types to create more complex data objects."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 259,
+   "id": "ecd3864c-514c-4f44-aa81-cd273c231e36",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "[('Jive', 26), ('Nova', 27), ('Astron', 209)]\n"
+     ]
+    }
+   ],
+   "source": [
+    "organizations = []\n",
+    "organizations.append((\"Jive\", 26))\n",
+    "organizations.append((\"Nova\", 27))\n",
+    "organizations.append((\"Astron\", 209))\n",
+    "print(organizations)"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "5b30ebd2-d41d-479d-b472-8d81437e1d5e",
+   "metadata": {},
+   "source": [
+    "So when are tuples useful? If you don't want to have the data changed. It is also slightly more memory efficient since it can't be extended. This requirement does not come up often but the wish to extend or remove data is so lists are more popular then tuples.\n",
+    "\n",
+    "Although not enforced by the language we see tuples more used a containers of different types and lists as a container for single types. "
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "91495e4b-450b-4204-a8e7-c98773cc6dd2",
+   "metadata": {},
+   "source": [
+    "### sets\n"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "b67c0e38-d444-4dc7-945f-0a2cd9b9ffd9",
+   "metadata": {},
+   "source": [
+    "A set is an container for distinct hashable objects. This means it can contain only unique values.\n",
+    "\n",
+    "A set is created with the curly braces characters '{' and '}'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 262,
+   "id": "de9a88b4-ebd6-4cc3-8daa-73646a32a4c2",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "{'Nova', 'Astron', 'Jive'}\n"
+     ]
+    }
+   ],
+   "source": [
+    "individuals = {\"Astron\", \"Jive\", \"Nova\", \"Nova\"}\n",
+    "print(individuals)"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "6636255a-9de5-4d14-b210-33aed1dd7079",
+   "metadata": {},
+   "source": [
+    "So what could we do with sets? We could get all the unique items out of a big list. Say we get a list of all the LOFAR stations that had an issue during an observation in the October. We could ask with a set which stations were had an issue during October."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 263,
+   "id": "42459f5d-0412-4204-8f57-67468767e416",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "{'CS001', 'CS003', 'FR606', 'CS002'}\n"
+     ]
+    }
+   ],
+   "source": [
+    "obs1 = ['CS001']\n",
+    "obs2 = ['CS001', 'CS002']\n",
+    "obs3 = ['CS003']\n",
+    "obs4 = ['FR606', 'CS002']\n",
+    "\n",
+    "unique = set(obs1 + obs2 + obs3 + obs4)\n",
+    "print(unique)"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "5824f33b-aef8-42c8-95c6-1cc7fe14add1",
+   "metadata": {},
+   "source": [
+    "Or we could take out reserved stations from all the stations."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 264,
+   "id": "d78e8f01-b665-4864-b779-704d8bf83c47",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "{'CS001', 'CS003', 'CS004'}\n"
+     ]
+    }
+   ],
+   "source": [
+    "stations = {'CS001', 'CS002', 'CS003', 'CS004'}\n",
+    "reserved = {'CS002'}\n",
+    "\n",
+    "usable = stations - reserved\n",
+    "print(usable)"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "56b0535e-f4df-46e0-874c-65e679227a67",
+   "metadata": {},
+   "source": [
+    "Or check for overlap:"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 265,
+   "id": "4f71e542-a66a-4dcd-ad1e-73a2de07c24e",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "{'CS003', 'CS002'}\n"
+     ]
+    }
+   ],
+   "source": [
+    "obs1 = {'CS002', 'CS003', 'CS004'}\n",
+    "obs2 = {'CS001', 'CS002', 'CS003'}\n",
+    "\n",
+    "both = obs1 & obs2\n",
+    "print(both)"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "c233a169-c95f-48a0-a5b4-24ee6f9807c2",
+   "metadata": {},
+   "source": [
+    "### dictionaries\n",
+    "\n",
+    "Dictionaries is a useful compound data type that is a set of key value pairs. They are also created by using curly braces but now it contains a key value pair."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 266,
+   "id": "601c3f43-6226-45ac-85bf-d335f6ad8953",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "{'name': 'CasA', 'size': 20}\n"
+     ]
+    }
+   ],
+   "source": [
+    "item = {'name': \"CasA\", 'size': 20}\n",
+    "print(item)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 269,
+   "id": "483d5667-9b7b-49fe-8e1f-33ddb0cd7221",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "{'Dwingeloo': '0521', 'Assen': '0592'}\n"
+     ]
+    }
+   ],
+   "source": [
+    "net_code = {'Dwingeloo': '0521', 'Assen': '0592'}\n",
+    "print(net_code)"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "a3aa915b-4b91-44c5-ab8c-12cf62a30674",
+   "metadata": {},
+   "source": [
+    "One can ask for all the values in a dictionary with .values() and all the keys with .keys()"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 270,
+   "id": "37390c12-2f84-45de-82a2-4610b9c9fefb",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "dict_keys(['Dwingeloo', 'Assen'])\n"
+     ]
+    }
+   ],
+   "source": [
+    "net_code = {'Dwingeloo': '0521', 'Assen': '0592'}\n",
+    "print(net_code.keys())"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 272,
+   "id": "1d5f6026-4e44-4f9e-8bec-8c7a3fef1ceb",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "dict_values(['0521', '0592'])\n"
+     ]
+    }
+   ],
+   "source": [
+    "net_code = {'Dwingeloo': '0521', 'Assen': '0592'}\n",
+    "print(net_code.values())"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "d5ec52d1-7e41-4439-b4a8-a46caf0de825",
+   "metadata": {},
+   "source": [
+    "### Exercise\n",
+    "\n",
+    "Create a program where you ask the user for a multiple items where you ask for some properties for each item. The properties can be stored in a dictionary and be added to a list. Print the list in the end. Try to use functions as well."
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "13e86fa7-c3ab-45fd-a1c0-876cc51c89c0",
+   "metadata": {},
+   "source": [
+    "## Flow control\n",
+    "\n",
+    "In flow control we decide to run or skip certain code based on truth values. Python has the two object True and False reserved as truth values. The meaning of these objects is quite self explanetory.\n",
+    "\n"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "b35aee31-6f50-4bf2-9abb-94ec9df038b5",
+   "metadata": {},
+   "source": [
+    "### If\n"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "0dfd5dd3-328d-445f-97b1-1ac26a48a0e5",
+   "metadata": {},
+   "source": [
+    "### While\n"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "00fa41bf-a364-49d0-9608-71508a7f1044",
+   "metadata": {},
+   "source": [
+    "### For\n"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "0d025fb4-d651-431b-96fc-2605d2c18385",
+   "metadata": {},
+   "source": [
     "### Break / Continue"
    ]
   },
@@ -2112,6 +3181,7 @@
     "* https://en.wikipedia.org/wiki/Computer_programming\n",
     "* https://python.org\n",
     "* Book - Automate the boring stuff with python : https://automatetheboringstuff.com/#toc\n",
+    "* Coding style - Pep8 : https://www.python.org/dev/peps/pep-0008/\n",
     "\n",
     "## Community\n",
     "\n",
-- 
GitLab