diff --git a/Session_1.ipynb b/Session_1.ipynb new file mode 100755 index 0000000..ccabf87 --- /dev/null +++ b/Session_1.ipynb @@ -0,0 +1,1078 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "# An introduction to Python\n", + "\n", + "## Session 1:\n", + "\n", + "- [Printing values](#Printing-values)\n", + "- [Using variables](#Using-variables)\n", + "- [Simple data types](#Simple-data-types): [Booleans](#Booleans), [Integers](#Integers), [Floating point numbers](#Floating-point-numbers), and [Strings](#Strings)\n", + "- [Comments](#Comments)\n", + "- [Exercises 1.1.1](#Exercises-1.1.1)\n", + "- [Arithmetic](#Arithmetic)\n", + "- [Exercises 1.1.2](#Exercises-1.1.2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## My Mantra of how to learn a new programming language\n", + "\n", + "- Learn Data Types\n", + "- Learn Control Structures\n", + "- Practice" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## Printing values\n", + "\n", + "The first bit of python syntax we're going to learn is the print statement. This command lets us print messages to the user, and also to see what Python thinks is the value of some expression (very useful when debugging your programs).\n", + "\n", + "We will go into details later on, but for now just note that to print some text you have to enclose it in \"quotation marks\". \n", + "\n", + "We will go into detail on the arithmetic operations supported in python shortly, but you can try exploring python's calculating abilities." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import sys #we have to import the package first." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3.6.2 |Anaconda, Inc.| (default, Sep 30 2017, 18:42:57) \n", + "[GCC 7.2.0]\n" + ] + } + ], + "source": [ + "print (sys.version) #the method \"version\" inside the package gives us the version of currently used python" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "slideshow": { + "slide_type": "fragment" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello from python!\n" + ] + } + ], + "source": [ + "print(\"Hello from python!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "slideshow": { + "slide_type": "fragment" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "34\n" + ] + } + ], + "source": [ + "print(34)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "slideshow": { + "slide_type": "fragment" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5\n" + ] + } + ], + "source": [ + "print(2 + 3) " + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "You can print multiple expressions you need to seperate them with commas. Python will insert a space between each element, and a newline at the end of the message (though you can suppress this behaviour by leaving a trailing comma at the end of the command)." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "slideshow": { + "slide_type": "fragment" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The answer: 42\n" + ] + } + ], + "source": [ + "print(\"The answer:\", 42)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## Using variables" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the print commands above we have directly operated on values such as text strings and numbers. When programming we will typically want to deal with rather more complex expressions where it is useful to be able to assign a name to an expression, especially if we are trying to deal with multiple values at the same time.\n", + "\n", + "We can give a name to a value using _variables_, the name is apt because the values stored in a variable can _vary_. Unlike some other languages, the type of value assigned to a variable can also change (this is one of the reasons why python is known as a _dynamic_ language).\n", + "\n", + "A variable can be assigned to a simple value..." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], + "source": [ + "x = 3 \n", + "print(x)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "... or the outcome of a more complex expression." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n" + ] + } + ], + "source": [ + "x = 2 + 2\n", + "print(x)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "A variable can be called whatever you like (as long as it starts with a character, it does not contain space and is meaningful) and you assign a value to a variable with the **`=` operator**. Note that this is different to mathematical equality (which we will come to later...)\n", + "\n", + "You can print a variable to see what python thinks its current value is." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Iron man is his name\n" + ] + } + ], + "source": [ + "name = \"Iron man\"\n", + "print(name, \"is his name\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the interactive interpreter you don't have to print everything, if you type a variable name (or just a value), the interpreter will automatically print out what python thinks the value is. Note though that this is not the case if your code is in a file." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "7" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "3 + 4" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "15" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x = 5\n", + "3 * x" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Variables can be used on the right hand side of an assignment as well, in which case they will be evaluated before the value is assigned to the variable on the left hand side." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "15\n" + ] + } + ], + "source": [ + "x = 5\n", + "y = x * 3\n", + "print(y)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "or just `y` in the interpreter and in Jupyter notebook" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "15" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "y" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can use the current value of a variable itself in an assignment" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "16" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "y = y + 1\n", + "y" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In fact this is such a common idiom that there are special operators that will do this implicitly (more on these later)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "17" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "y += 1\n", + "y" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Simple data types" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Python (and computers in general) treats different types of data differently. Python has 5 main basic data types. Types are useful to constrain some operations to a certain category of variables. For example it doesn't really make sense to try to divide a string.\n", + "\n", + "We will see some examples of these in use shortly, but for now let's see all of the basic types available in python.\n", + "\n", + "### Booleans\n", + "\n", + "Boolean values represent truth or falsehood, as used in logical operations, for example. Not surprisingly, there are only two values, and in Python they are called True and False." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True False\n", + "False\n" + ] + } + ], + "source": [ + "a = True\n", + "b = False\n", + "print(a, b)\n", + "\n", + "x = 10 < 5\n", + "print(x)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Integers\n", + "\n", + "Integers represent whole numbers, as you would use when counting items, and can be positive or negative." + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-7 123\n" + ] + } + ], + "source": [ + "i = -7\n", + "j = 123\n", + "print(i, j)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Floating point numbers\n", + "\n", + "Floating point numbers, often simply referred to as floats, are numbers expressed in the decimal system, i.e. 2.1, 999.998, -0.000004 etc. The value 2.0 would also be interpreted as a floating point number, but the value 2, without the decimal point will not; it will be interpreted as an integer." + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-132.889257\n" + ] + } + ], + "source": [ + "x = 3.14159\n", + "y = -42.3\n", + "print(x * y)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Floating point numbers can also carry an e suffix that states which power of ten they operate at." + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1500.0\n", + "0.03\n" + ] + } + ], + "source": [ + "k = 1.5e3\n", + "l = 3e-2\n", + "print(k)\n", + "print(l)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Strings\n", + "\n", + "Strings represent text, i.e. \"strings\" of characters. They can be delimited by single quotes or double quotes , but you have to use the same delimiter at both ends. Unlike some programming languages, such as Perl, there is no difference between the two types of quote, although using one type does allow the other type to appear inside the string as a regular character.\n", + "\n", + "Normally a python statement ends at the end of the line, but if you want to type a string over several lines you can enclose it in triple quotation marks." + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'A string that extends\\nover multiple lines'" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s = \"String with double quotes\"\n", + "t = 'String with single quotes'\n", + "u = \"It's a string with apostrophes\"\n", + "\"\"\"A string that extends\n", + "over multiple lines\"\"\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### The None object\n", + "\n", + "The None object is special built-in value which can be thought of as **representing nothingness or that something is undefined**. For example, it can be used to indicate that a variable exists, but has not yet been set to anything specific." + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "None\n" + ] + } + ], + "source": [ + "z = None\n", + "print(z)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Object type\n", + "\n", + "You can check what type python thinks an expression is with the type function, which you can call with the name type immediately followed by parentheses enclosing the expression you want to check (either a variable or a value), e.g. type(3). (This is the general form for calling functions, we'll see lots more examples of functions later...)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True is of \n" + ] + } + ], + "source": [ + "a = True\n", + "print(a, \"is of\", type(a))" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-7 is of \n" + ] + } + ], + "source": [ + "i = -7\n", + "print(i, \"is of\", type(i))" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "12.7893 is of \n" + ] + } + ], + "source": [ + "x = 12.7893\n", + "print(x, \"is of\", type(x))" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Workshop is of \n" + ] + } + ], + "source": [ + "s = \"Workshop\"\n", + "print(s, \"is of\", type(s))" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "None is of \n" + ] + } + ], + "source": [ + "z = None\n", + "print(z, \"is of\", type(z))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Comments\n", + "\n", + "When you are writing a program it is often convenient to annotate your code to remind you what you were (intending) it to do. In programming these annotations are known as _comments_. You can include a comment in python by prefixing some text with a # character. All text following the # will then be ignored by the interpreter. You can start a comment on its own line, or you can include it at the end of a line of code.\n", + "\n", + "It is also often useful to temporarily remove some code from a script without deleting it. This is known as _commenting out_ some code." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "print(\"Hi\") # this will be ignored\n", + "# as will this\n", + "print(\"Bye\")\n", + "# print \"Never seen\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercises 1.1.1\n", + "\n", + "To start the Python interpreter, open a terminal window, type the command `python`, then enter Python commands after the prompt `>>>` and press `Enter` when you're done. \n", + "\n", + "Python will run the code you typed, and might display some output on the line below, before leaving you with another prompt which looks like `>>>`.\n", + "\n", + "If you want to exit the interactive interpreter you can type the command `quit()` or type `Ctrl-D`.\n", + "\n", + "In the interpreter:\n", + "\n", + "1. Create a variable and assign it the string value of your first name, assign your age to another variable (you are free to lie!), print out a message saying how old you are\n", + "2. Use the addition operator to add 10 to your age and print out a message saying how old you will be in 10 years time" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Arithmetic" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Python supports all the standard arithmetical operations on numerical types, and mostly uses a similar syntax to several other computer languages:" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "x = 4.5 y = 2\n", + "addition x + y = 6.5\n", + "subtraction x - y = 2.5\n", + "multiplication x * y = 9.0\n", + "division x / y = 2.25\n" + ] + } + ], + "source": [ + "x = 4.5\n", + "y = 2\n", + "\n", + "print('x = ', x, 'y = ', y)\n", + "print('addition x + y =', x + y) \n", + "print('subtraction x - y =', x - y) \n", + "print('multiplication x * y =', x * y) \n", + "print('division x / y =', x / y) " + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "x = 4.5 y = 2\n", + "division x / y = 2.25\n", + "floored division x // y = 2.0\n", + "\n", + "modulus (remainder of x/y) x % y = 0.5\n", + "exponentiation x ** y = 100\n" + ] + } + ], + "source": [ + "x = 4.5\n", + "y = 2\n", + "\n", + "print('x = ', x, 'y = ', y)\n", + "print('division x / y =', x / y)\n", + "print('floored division x // y =', x // y)\n", + "print(type(x//y))\n", + "print('modulus (remainder of x/y) x % y =', x % y) \n", + "print('exponentiation x ** y =', 10 ** 2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As usual in maths, division and multiplication have higher precedence than addition and subtraction, but arithmetic expressions can be grouped using parentheses to override the default precedence" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "x = 13\n", + "y = 5\n", + "\n", + "print('x * (2 + y) =', x * (2 + y))\n", + "print('(x * 2) + y =', (x * 2) + y)\n", + "print('x * 2 + y =', x * 2 + y)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can mix (some) types in arithmetic expressions and python will apply rules as to the type of the result\n" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "18" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "int(13 + 5.0)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can force python to use a particular type by converting an expression explicitly, using helpful named functions: float, int, str etc." + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "10.0" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "float(3) + float(7)" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "int(3.14159) + 1\n", + "\n", + "+1+1" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The addition operator `+` allows you also to concatenate strings together." + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "number3\n" + ] + } + ], + "source": [ + "print('number' + str(3))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Division in Python 2 sometimes trips up new (and experienced!) programmers. If you divide 2 integers you will only get an integer result. If you want a floating point result you should explicitly cast at least one of the arguments to a float." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3/4 = 0.75\n", + "3.0/4 = 0.75\n", + "float(3)/4 = 0.75\n" + ] + } + ], + "source": [ + "print(\"3/4 =\", 3/4)\n", + "print(\"3.0/4 =\", 3.0/4)\n", + "print(\"float(3)/4 =\", float(3)/4)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "There are a few shortcut assignment statements to make modifying variables directly faster to type" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x = 3\n", + "x += 1 # equivalent to x = x + 1\n", + "x" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "20" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x = 2\n", + "y = 10\n", + "y *= x\n", + "y" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "These shortcut operators are available for all arithmetic and logical operators." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercises 1.1.2\n", + "\n", + "In the interpreter:\n", + "\n", + "1. Assign numerical values to 2 variables, calculate the mean of these two variables and store the result in another variable. Print out the result to the screen." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Next Session\n", + "\n", + "[Go to next session](Session_2.ipynb)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Session_2.ipynb b/Session_2.ipynb new file mode 100755 index 0000000..a2ebc51 --- /dev/null +++ b/Session_2.ipynb @@ -0,0 +1,1387 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "# An introduction to Python\n", + "\n", + "## Session 1.2: Collections\n", + "\n", + "- [Tuples](#Tuples), [Lists](#Lists) and [Manipulating tuples and lists](#Manipulating-tuples-and-lists) | [Exercise 1.2.1](#Exercise-1.2.1)\n", + "- [String manipulations](#String-manipulations) | [Exercise 1.2.2](#Exercise-1.2.2)\n", + "- [Sets](#Sets) |\n", + "- [Dictionnaries](#Dictionnaries) |" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As well as the basic data types we introduced above, very commonly you will want to store and operate on collections of values, and python has several _data structures_ that you can use to do this. The general idea is that you can place several items into a single collection and then refer to that collection as a whole. Which one you will use will depend on what problem you are trying to solve.\n", + "\n", + "## Tuples\n", + "\n", + "- Can contain any number of items\n", + "- Can contain different types of items\n", + "- __Cannot__ be altered once created (they are immutable)\n", + "- Items have a defined order\n", + "\n", + "A tuple is created by using round brackets around the items it contains, with commas seperating the individual elements." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(123, 54, 92)\n", + "()\n", + "('Ala',)\n", + "(2, 3, False, 'Arg', None)\n" + ] + } + ], + "source": [ + "a = (123, 54, 92) # tuple of 3 integers\n", + "b = () # empty tuple\n", + "c = (\"Ala\",) # tuple of a single string (note the trailing \",\")\n", + "d = (2, 3, False, \"Arg\", None) # a tuple of mixed types\n", + "\n", + "print(a)\n", + "print(b)\n", + "print(c)\n", + "print(d)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can of course use variables in tuples and other data structures" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "x = 1.2\n", + "y = -0.3\n", + "z = 0.9\n", + "t = (x, y, z)\n", + "\n", + "print(t)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Tuples can be _packed_ and _unpacked_ with a convenient syntax. The number of variables used to unpack the tuple must match the number of elements in the tuple." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "t = 2, 3, 4 # tuple packing\n", + "print('t is', t)\n", + "x, y, z = t # tuple unpacking\n", + "print('x is', x)\n", + "print('y is', y)\n", + "print('z is', z)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Lists\n", + "\n", + "- Can contain any number of items\n", + "- Can contain different types of items\n", + "- __Can__ be altered once created (they are _mutable_)\n", + "- Items have a particular order\n", + "\n", + "Lists are created with square brackets around their items:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 3, 9, 'Py', 217.213]\n", + "['Python']\n", + "[]\n" + ] + } + ], + "source": [ + "a = [1, 3, 9, 'Py', 217.213]\n", + "b = [\"Python\"]\n", + "c = []\n", + "\n", + "print(a)\n", + "print(b)\n", + "print(c)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Lists and tuples can contain other list and tuples, or any other type of collection:" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "r\n", + "ff\n", + "fd\n", + "sd\n", + "[['r', 'ff'], ['fd', 'sd']]\n" + ] + } + ], + "source": [ + "matrix = [[input(),input()], [input(),input()]]\n", + "print(matrix)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can convert between tuples and lists with the tuple and list functions. Note that these create a new collection with the same items, and leave the original unaffected." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "a = (1, 4, 9, 16) # A tuple of numbers\n", + "b = ['A','B','C','d'] # A list of characters\n", + "\n", + "print(a)\n", + "print(b)\n", + "\n", + "l = list(a) # Make a list based on a tuple \n", + "print(l)\n", + "\n", + "t = tuple(b) # Make a tuple based on a list\n", + "print(t)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Manipulating tuples and lists\n", + "\n", + "Once your data is in a list or tuple, python supports a number of ways you can access elements of the list and manipulate the list in useful ways, such as sorting the data.\n", + "\n", + "Tuples and lists can generally be used in very similar ways." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Index access\n", + "\n", + "You can access individual elements of the collection using their _index_, note that the first element is at index 0. Negative indices count backwards from the end." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t is (123, 54, 92, 87, 33)\n", + "t[0] is 123\n", + "t[2] is 92\n", + "x is [123, 54, 92, 87, 33]\n", + "x[-1] is 33\n" + ] + } + ], + "source": [ + "t = (123, 54, 92, 87, 33)\n", + "x = [123, 54, 92, 87, 33]\n", + "\n", + "print('t is', t)\n", + "print('t[0] is', t[0])\n", + "print('t[2] is', t[2])\n", + "\n", + "print('x is', x)\n", + "print('x[-1] is', x[-1])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Slices\n", + "\n", + "You can also access a range of items, known as _slices_, from inside lists and tuples using a colon `:` to indicate the beginning and end of the slice inside the square brackets. **Note that the slice notation `[a:b]` includes positions from `a` up to _but not including_ `b`**." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t[1:3] is (54, 92)\n", + "x[2:] is [92, 87, 33]\n", + "x[:-1] is [123, 54, 92, 87]\n" + ] + } + ], + "source": [ + "t = (123, 54, 92, 87, 33)\n", + "x = [123, 54, 92, 87, 33]\n", + "print('t[1:3] is', t[1:3])\n", + "print('x[2:] is', x[2:])\n", + "print('x[:-1] is', x[:-1])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### `in` operator\n", + "You can check if a value is in a tuple or list with the in operator, and you can negate this with not" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "123 in [123, 54, 92, 87, 33] True\n", + "234 in (123, 54, 92, 87, 33) False\n", + "999 not in [123, 54, 92, 87, 33] True\n" + ] + } + ], + "source": [ + "t = (123, 54, 92, 87, 33)\n", + "x = [123, 54, 92, 87, 33]\n", + "print('123 in', x, 123 in x)\n", + "print('234 in', t, 234 in t)\n", + "print('999 not in', x, 999 not in x)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[3, 4, 5]" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = [1, 2, 3, 4, 5]\n", + "\n", + "a[2:]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### `len()` and `count()` functions\n", + "You can get the length of a list or tuple with the in-built len() function, and you can count the number of particular elements contained in a list with the .count() function." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "length of t is 5\n", + "number of 33s in x is 1\n" + ] + } + ], + "source": [ + "t = (123, 54, 92, 87, 33)\n", + "x = [123, 54, 92, 87, 33]\n", + "print(\"length of t is\", len(t))\n", + "print(\"number of 33s in x is\", x.count(33))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Modifying lists\n", + "You can alter lists in place, but not tuples" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[123, 54, 92, 87, 33]\n", + "[123, 54, 33, 87, 33]\n" + ] + } + ], + "source": [ + "x = [123, 54, 92, 87, 33]\n", + "print(x)\n", + "x[2] = 33\n", + "print(x)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Tuples _cannot_ be altered once they have been created, if you try to do so, you'll get an error." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(123, 54, 92, 87, 33)\n" + ] + }, + { + "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\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mt\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;36m123\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m54\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m92\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m87\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m33\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mt\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m4\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": [ + "t = (123, 54, 92, 87, 33)\n", + "print(t)\n", + "t[1] = 4" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can add elements to the end of a list with append()" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[123, 54, 92, 87, 33, 101]\n" + ] + } + ], + "source": [ + "x = [123, 54, 92, 87, 33]\n", + "x.append(101)\n", + "print(x)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "or insert values at a certain position with insert(), by supplying the desired position as well as the new value" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[123, 54, 92, 1111, 87, 33]\n" + ] + } + ], + "source": [ + "x = [123, 54, 92, 87, 33]\n", + "x.insert(3, 1111)\n", + "print(x)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can remove values with remove()" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[54, 92, 87, 33]\n" + ] + } + ], + "source": [ + "x = [123, 54, 92, 87, 33]\n", + "x.remove(123)\n", + "print(x)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and delete values by index with del" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[123, 54, 92, 87, 33]\n", + "[54, 92, 87, 33]\n" + ] + } + ], + "source": [ + "x = [123, 54, 92, 87, 33]\n", + "print(x)\n", + "del x[0]\n", + "print(x)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It's often useful to be able to combine arrays together, which can be done with extend() (as append would add the whole list as a single element in the list)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 2, 3, 4, 5, 6]\n", + "[1, 2, 3, 4, 5, 6, [4, 5, 6]]\n" + ] + } + ], + "source": [ + "a = [1,2,3]\n", + "b = [4,5,6]\n", + "a.extend(b)\n", + "print(a)\n", + "a.append(b)\n", + "print(a)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The plus symbol + is shorthand for the extend operation when applied to lists:" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 2, 3, 4, 5, 6]\n" + ] + } + ], + "source": [ + "a = [1, 2, 3]\n", + "b = [4, 5, 6]\n", + "a = a + b\n", + "print(a)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Slice syntax can be used on the left hand side of an assignment operation to assign subregions of a list" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 9, 9, 9, 9, 4, 5, 6]\n" + ] + } + ], + "source": [ + "a = [1, 2, 3, 4, 5, 6]\n", + "a[1:3] = [9, 9, 9, 9]\n", + "print(a)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can change the order of elements in a list" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[2, 4, 5, 3, 1]\n", + "[1, 2, 3, 4, 5]\n" + ] + } + ], + "source": [ + "a = [1, 3, 5, 4, 2]\n", + "a.reverse()\n", + "print(a)\n", + "#print(a[::2])\n", + "a.sort()\n", + "print(a)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Note that both of these change the list, if you want a sorted copy of the list while leaving the original untouched, use sorted()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "a = [2, 5, 7, 1]\n", + "b = sorted(a)\n", + "print(a)\n", + "print(b)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## String manipulations\n", + "\n", + "Strings are a lot like tuples of characters, and individual characters and substrings can be accessed and manipulated using similar operations we introduced above.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "A\n", + "G\n", + "ABCDEF\n", + "True\n", + "True\n", + "8\n" + ] + } + ], + "source": [ + "text = \"ABCDEFGH\"\n", + "print(text[0])\n", + "print(text[-2])\n", + "print(text[0:6])\n", + "print(\"EFG\" in text)\n", + "print(\"ABC\" in text)\n", + "print(len(text))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Just as with tuples, trying to assign a value to an element of a string results in an error" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "'str' 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\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mtext\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"ABCDEFGH\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mtext\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"CCC\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m: 'str' object does not support item assignment" + ] + } + ], + "source": [ + "text = \"ABCDEFGH\"\n", + "text[0:2] = \"CCC\" " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Python provides a number of useful functions that let you manipulate strings\n", + "\n", + "The in operator lets you check if a substring is contained within a larger string, but it does not tell you where the substring is located. This is often useful to know and python provides the .find() method which returns the index of the first occurrence of the search string, and the .rfind() method to start searching from the end of the string.\n", + "\n", + "If the search string is not found in the string both these methods return -1." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "CDE is at position: 2\n", + "The last C is at position: 6\n" + ] + } + ], + "source": [ + "string = \"ABCDEDCBA\"\n", + "index = string.find(\"CDE\")\n", + "print(\"CDE is at position:\", index)\n", + "index = string.rfind('C')\n", + "print(\"The last C is at position:\", index)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "When we are reading text from files (which we will see later on), often there is unwanted whitespace at the start or end of the string. We can remove leading whitespace with the .lstrip() method, trailing whitespace with .rstrip(), and whitespace from both ends with .strip().\n", + "\n", + "All of these methods return a copy of the changed string, so if you want to replace the original you can assign the result of the method call to the original variable." + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "27 My name is Python .\n", + "22 My name is Python .\n", + "22 My name is Python .\n", + "17 My name is Python .\n" + ] + } + ], + "source": [ + "s = \" My name is Python \"\n", + "print(len(s), s, \".\")\n", + "print(len(s.rstrip()), s.rstrip(), \".\")\n", + "print(len(s.lstrip()), s.lstrip(), \".\")\n", + "print(len(s.strip()), s.strip(),\".\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can split a string into a list of substrings using the .split() method, supplying the delimiter as an argument to the method. If you don't supply any delimiter the method will split the string on whitespace by default (which is very often what you want!)\n", + "\n", + "To split a string into its component characters you can simply _cast_ the string to a list " + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['My', 'name', 'is', 'Python']\n", + "['M', 'y', ' ', 'n', 'a', 'm', 'e', ' ', 'i', 's', ' ', 'P', 'y', 't', 'h', 'o', 'n']\n" + ] + } + ], + "source": [ + "string = \"My name is Python\"\n", + "words = string.split(\" \")\n", + "print(words)\n", + "\n", + "letters = list(string) # a tuple of character converted into a list\n", + "print(letters)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + ".split() is the counterpart to the .join() method that lets you join the elements of a list into a string only if all the elements are of type String:" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['My', 'name', 'is', 'Python']\n", + "My|name|is|Python\n" + ] + } + ], + "source": [ + "string = \"My name is Python\"\n", + "words = string.split(\" \")\n", + "print(words)\n", + "print(\"|\".join(words))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We also saw earlier that the + operator lets you concatenate strings together into a larger string.\n", + "\n", + "Note that this operator only works on variables of the same type. If you want to concatenate a string with an integer (or some other type), first you have to cast the integer to a string with the str() function." + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Python3.6\n" + ] + } + ], + "source": [ + "language = \"Python\"\n", + "version = 3.6\n", + "print(language + str(version))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercise 1.2.2\n", + "\n", + "1. Create a string variable with your full name in it, with your first and last name (and any middle names) seperated by a space. Split the string into a list, and print out your surname.\n", + "2. Check if your surname contains the letter \"E\", and print out the position of this letter in the string. Try a few other letters.\n", + "\n", + "### Optional exercise\n", + "- Use a format string to print out your first name and the length of your first name by looking into the python library for String formating https://docs.python.org/3/library/stdtypes.html#str.format and https://docs.python.org/3/library/string.html#formatstrings using `str.format()`" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Sets\n", + "\n", + "- Sets contain unique elements, i.e. no repeats are allowed\n", + "- The elements in a set do not have an order\n", + "- Sets cannot contain elements which can be internally modified (e.g. lists and dictionaries)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "l = [1, 2, 3, 2, 3] # list of 5 values\n", + "s = set(l) # set of 3 unique values\n", + "print(s)\n", + "e = set() # empty set\n", + "print(e)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Sets are very similar to lists and tuples and you can use many of the same operators and functions, except they are **inherently unordered**, so they don't have an index, and can only contain _unique_ values, so adding a value already in the set will have no effect" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "s = set([1, 2, 3, 2, 3])\n", + "print(s)\n", + "print(\"number in set:\", len(s))\n", + "s.add(4)\n", + "print(s)\n", + "s.add(3)\n", + "print(s)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can remove specific elements from the set." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "s = set([1, 2, 3, 2, 3])\n", + "print(s)\n", + "s.remove(3)\n", + "print(s)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can do all the expected logical operations on sets, such as taking the union or intersection of 2 sets with the | _or_ and & _and_ operators " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "s1 = set([2, 4, 6, 8, 10])\n", + "s2 = set([4, 5, 6, 7])\n", + "\n", + "print(\"Union:\", s1 | s2)\n", + "print(\"Intersection:\", s1 & s2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Dictionaries\n", + "\n", + "Lists are useful in many contexts, but often we have some data that has no inherent order and that we want to access by some useful name rather than an index. For example, as a result of some experiment we may have a set of genes and corresponding expression values. We could put the expression values in a list, but then we'd have to remember which index in the list corresponded to which gene and this would quickly get complicated.\n", + "\n", + "For these situations a _dictionary_ is a very useful data structure.\n", + "\n", + "Dictionaries:\n", + "\n", + "- Contain a mapping of keys to values (like a word and its corresponding definition in a dictionary)\n", + "- The keys of a dictionary are unique, i.e. they cannot repeat\n", + "- The values of a dictionary can be of any data type\n", + "- The keys of a dictionary cannot be an internally modifiable type (e.g. lists, but you can use tuples)\n", + "- Dictionaries do not store data in any particular order" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'A': 'Cricket', 'B': 'Football', 'C': 'Hockey', 'D': 'Badminton'}\n" + ] + }, + { + "data": { + "text/plain": [ + "'Hockey'" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sports = {\"A\": \"Cricket\", \"B\": \"Football\", \"C\": \"Hockey\", \"D\": \"Badminton\"}\n", + "print(sports)\n", + "\n", + "sports['C']" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can access values in a dictionary using the key inside square brackets" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "sports = {\"A\": \"Cricket\", \"B\": \"Football\", \"C\": \"Hockey\", \"D\": \"Badminton\"}\n", + "print(\"A represents\", sports[\"A\"])\n", + "print(\"G represents\", sports[\"G\"])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "An error is triggered if a key is absent from the dictionary:" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "ename": "KeyError", + "evalue": "'N'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0msports\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m\"A\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m\"Cricket\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"B\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m\"Football\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"C\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m\"Hockey\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"D\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m\"Badminton\"\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"What about N?\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msports\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"N\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mKeyError\u001b[0m: 'N'" + ] + } + ], + "source": [ + "sports = {\"A\": \"Cricket\", \"B\": \"Football\", \"C\": \"Hockey\", \"D\": \"Badminton\"}\n", + "print(\"What about N?\", sports[\"N\"])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can access values safely with the get method, which gives back None if the key is absent and you can also supply a default values" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "What about N? None\n", + "With a default value: asfasfasf\n" + ] + } + ], + "source": [ + "sports = {\"A\": \"Cricket\", \"B\": \"Football\", \"C\": \"Hockey\", \"D\": \"Badminton\"}\n", + "print(\"What about N?\", sports.get(\"N\"))\n", + "print(\"With a default value:\", sports.get(\"N\", \"asfasfasf\"))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can check if a key is in a dictionary with the in operator, and you can negate this with not" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sports = {\"A\": \"Cricket\", \"B\": \"Football\", \"C\": \"Hockey\", \"D\": \"Badminton\"}\n", + "\"T\" in sports" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sports = {\"A\": \"Cricket\", \"B\": \"Football\", \"C\": \"Hockey\", \"D\": \"Badminton\"}\n", + "\"Y\" not in sports" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The len() function gives back the number of (key, value) pairs in the dictionary:" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n" + ] + } + ], + "source": [ + "sports = {\"A\": \"Cricket\", \"B\": \"Football\", \"C\": \"Hockey\", \"D\": \"Badminton\"}\n", + "print(len(sports))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can introduce new entries in the dictionary by assigning a value with a new key:" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'A': 'Cricket', 'B': 'Football', 'C': 'Hockey', 'D': 'Badminton', 'E': 'Kabaddi'}\n" + ] + } + ], + "source": [ + "sports = {\"A\": \"Cricket\", \"B\": \"Football\", \"C\": \"Hockey\", \"D\": \"Badminton\"}\n", + "sports['E'] = 'Kabaddi'\n", + "print(sports)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can change the value for an existing key by reassigning it:" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'A': 'Cricket', 'B': 'Football', 'C': 'Hockey', 'D': 'Badminton', 'E': 'Kabaddi', 'F': 'Volley Ball'}\n" + ] + } + ], + "source": [ + "sports = {\"A\": \"Cricket\", \"B\": \"Football\", \"C\": \"Hockey\", \"D\": \"Badminton\", \"E\": \"Kabaddi\"}\n", + "sports['F'] = 'Volley Ball'\n", + "print(sports)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can delete entries from the dictionary:" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'A': 'Cricket', 'B': 'Football', 'C': 'Hockey', 'D': 'Badminton', 'E': 'Kabaddi'}\n" + ] + } + ], + "source": [ + "sports = {\"A\": \"Cricket\", \"B\": \"Football\", \"C\": \"Hockey\", \"D\": \"Badminton\", \"E\": \"Kabaddi\", 'F': 'Volley Ball'}\n", + "del sports['F']\n", + "print(sports)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can get a list of all the keys (in arbitrary order) using the inbuilt .keys() function" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['A', 'B', 'C', 'D', 'E']\n" + ] + } + ], + "source": [ + "sports = {\"A\": \"Cricket\", \"B\": \"Football\", \"C\": \"Hockey\", \"D\": \"Badminton\", \"E\": \"Kabaddi\"}\n", + "print(list(sports.keys()))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "And equivalently get a list of the values:" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Cricket', 'Football', 'Hockey', 'Badminton', 'Kabaddi']\n" + ] + } + ], + "source": [ + "sports = {\"A\": \"Cricket\", \"B\": \"Football\", \"C\": \"Hockey\", \"D\": \"Badminton\", \"E\": \"Kabaddi\"}\n", + "print(list(sports.values()))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "And a list of tuples containing (key, value) pairs:" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[('A', 'Cricket'), ('B', 'Football'), ('C', 'Hockey'), ('D', 'Badminton'), ('E', 'Kabaddi')]\n" + ] + } + ], + "source": [ + "sports = {\"A\": \"Cricket\", \"B\": \"Football\", \"C\": \"Hockey\", \"D\": \"Badminton\", \"E\": \"Kabaddi\"}\n", + "print(list(sports.items()))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "collapsed": true + }, + "source": [ + "## Next Session\n", + "\n", + "- Go to next session: [Session 3](Session_3.ipynb)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/intro.ipynb b/intro.ipynb new file mode 100755 index 0000000..2ac21b5 --- /dev/null +++ b/intro.ipynb @@ -0,0 +1,751 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "nbpresent": { + "id": "dc7a1635-0bbd-4bf7-a07e-7a36f58e258b" + }, + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "# An introduction to Python" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "nbpresent": { + "id": "21082cb9-e1b9-4fe9-80d5-9d9e8418937b" + }, + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## Learning objectives\n", + "- **Basics** how to print, create variables and save Python code in files\n", + "- **List** the most common data types in Python\n", + "- **Explain** how to write conditions and loops in Python\n", + "- **Use and compare** these concepts in different code examples \n", + "- **Propose and create** solutions using these concepts in different exercises" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "nbpresent": { + "id": "8458de53-35b5-405e-a372-5db5d2e2c2c5" + }, + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## Course materials\n", + "\n", + "- All course materiel is available on [GitHub](https://github.com/sprajosh/basic-python)\n", + "- Follow along with the example code as you go through the material, and attempt the exercises to practice what you’ve learned\n", + "- Questions are welcome at any point!\n", + "- If you have specific projects/problems you like to use Python for we are happy to (try to) help.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "nbpresent": { + "id": "96ca5c44-2cfc-471c-8da7-39870c822e20" + }, + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## What is *Python*?\n", + "\n", + "- Python is a *dynamic, interpreted* general purpose programming language initially created by Guido van Rossum in 1991\n", + "- It is a powerful language that supports several popular programming paradigms:\n", + " - procedural\n", + " - object-oriented\n", + " - functional\n", + "- Python is widely used in bioinformatics and scientific computing, as well as many other fields and in industry\n", + "- Python is available on all popular operating systems\n", + " - Macs\n", + " - Windows\n", + " - Linux" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "nbpresent": { + "id": "9110098b-9675-4d64-adf3-c947073d4c4d" + }, + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## The Python programming language\n", + "\n", + "- Python is considered to come with \"batteries included\" and the standard library (some of which we will see in this course) provides built-in support for lots of common tasks:\n", + " - numerical & mathematical functions \n", + " - interacting with files and the operating system\n", + " - ...\n", + "\n", + "- There is also a wide range of external libraries for areas not covered in the standard library, such as [Pandas](http://pandas.pydata.org/) the Python Data Analysis Library" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "nbpresent": { + "id": "0d61b4b4-163f-47fe-80f1-092287218273" + }, + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## Getting started\n", + "\n", + "- Python is an *interpreted* language, this means that your computer does not run Python code natively, but instead we run our code using the Python interpreter\n", + "- There are three ways in which you can run Python code:\n", + " - Directly typing **commands into the interpreter**: *Good for experimenting with the language, and for some interactive work*\n", + " - Using a **Jupyter notebook**: *Great for experimenting with the language, and for sharing and learning*\n", + " - Typing code **into a file** and then telling the interpreter to run the code from this file: *Good for larger programs, and when you want to run the same code repeatedly*\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "nbpresent": { + "id": "b878a4f9-4345-4abb-81f4-5a731c639ab8" + }, + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## How to start the Python interpreter?\n", + "\n", + "- How you start the interpreter will depend on which operating system you are using, but on a Mac or Linux machine you should start a terminal and then just type the command `python3`\n", + "- This will print out some information about your installation of python and then leave you with a command prompt which looks like `>>>` \n", + "- You can then type commands and press `Enter` when you're done. Python will run the code you typed, and might display some output on the line below, before leaving you with another prompt.\n", + "- If you want to exit the interactive interpreter you can type the command `quit()` or type `Ctrl-D`" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "nbpresent": { + "id": "8a4ac456-6c4b-4249-8662-b1cabfd7cee4" + }, + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## The terminal\n", + "\n", + "We will see later how to save code in a file and run it.\n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "nbpresent": { + "id": "9814e8d7-60e0-43e6-aee0-3c33cc2cc809" + }, + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## What is a Jupyter notebook?\n", + "\n", + "
\n", + "\n", + "- The [Jupyter Notebook](http://jupyter.org/) is a web application that allows you to create and share documents that contain live code, equations, visualizations and explanatory text. \n", + "\n", + "- Jupyter provides a rich architecture for interactive data science and scientific computing with: \n", + " - Over 40 programming languages such as Python, R, Julia and Scala.\n", + " - A browser-based notebook with support for code, rich text, math expressions, plots and other rich media.\n", + " - Support for interactive data visualization.\n", + " - Easy to use tools for parallel computing." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "nbpresent": { + "id": "62fdd00c-a006-4f11-b9dc-e2ca072225d7" + }, + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## How to install Jupyter on your own computer?\n", + "\n", + "\n", + "\n", + "\n", + "
\n", + "\n", + "- [See Installing Jupyter Notebook](https://jupyter.readthedocs.io/en/latest/install.html)\n", + "\n", + "- For new users, we recommend [installing Anaconda](https://www.continuum.io/downloads). Anaconda conveniently installs Python, the Jupyter Notebook, and other commonly used packages for scientific computing and data science.\n", + "\n", + "- Start the notebook server from the command line:\n", + "```\n", + "jupyter-notebook\n", + "```\n", + "- You should see the notebook home page open in your web browser.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "nbpresent": { + "id": "0e25dad3-add0-466e-8f71-e771d6ec4500" + }, + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## How to run python in a Jupyter notebook?\n", + "\n", + "\n", + "
\n", + "\n", + "- See [Jupyter Notebook Basics](http://nbviewer.jupyter.org/github/jupyter/notebook/blob/master/docs/source/examples/Notebook/Notebook%20Basics.ipynb)\n", + "\n", + "\n", + "- Go to first session: [Session 1](Session_1.ipynb)" + ] + } + ], + "metadata": { + "anaconda-cloud": {}, + "celltoolbar": "Slideshow", + "kernelspec": { + "display_name": "Python 3", + "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.7.1" + }, + "nbpresent": { + "slides": { + "152c5a3b-78f9-4183-bce2-379a4012baf6": { + "id": "152c5a3b-78f9-4183-bce2-379a4012baf6", + "layout": "grid", + "prev": "5613e857-5b4e-42e4-9feb-df0440592ca2", + "regions": { + "20d6059c-7745-410d-a5fb-0b91cacbc2e2": { + "attrs": { + "height": 0.6666666666666666, + "pad": 0.01, + "treemap:weight": 1, + "width": 0.5, + "x": 0, + "y": 0 + }, + "id": "20d6059c-7745-410d-a5fb-0b91cacbc2e2" + }, + "300e6ccd-ecf4-425e-8574-3debe305aafb": { + "attrs": { + "height": 0.3333333333333333, + "pad": 0.01, + "treemap:weight": 1, + "width": 1, + "x": 0, + "y": 0.6666666666666666 + }, + "content": { + "cell": "9814e8d7-60e0-43e6-aee0-3c33cc2cc809", + "part": "whole" + }, + "id": "300e6ccd-ecf4-425e-8574-3debe305aafb" + }, + "df2dd6ff-570b-4b75-9cb7-1ff1dbdd4f55": { + "attrs": { + "height": 0.6666666666666666, + "pad": 0.01, + "treemap:weight": 1, + "width": 0.5, + "x": 0.5, + "y": 0 + }, + "id": "df2dd6ff-570b-4b75-9cb7-1ff1dbdd4f55" + } + } + }, + "2586ca7d-5091-40ea-b566-ccc5fbf833c6": { + "id": "2586ca7d-5091-40ea-b566-ccc5fbf833c6", + "prev": "f001d476-5814-4664-a722-f04f5d23cd52", + "regions": { + "d6011048-43db-4990-a82e-768683aa4fe5": { + "attrs": { + "height": 0.8, + "width": 0.8, + "x": 0.1, + "y": 0.1 + }, + "content": { + "cell": "ceb5f5a0-a5e8-435e-ae16-23c2ba8c6ab2", + "part": "whole" + }, + "id": "d6011048-43db-4990-a82e-768683aa4fe5" + } + } + }, + "27ee4130-d0bb-4287-b8fe-75a7b0ecf178": { + "id": "27ee4130-d0bb-4287-b8fe-75a7b0ecf178", + "prev": "2586ca7d-5091-40ea-b566-ccc5fbf833c6", + "regions": { + "7a689d66-0c9d-4492-928b-f35bfd2ffc4c": { + "attrs": { + "height": 0.8, + "width": 0.8, + "x": 0.1, + "y": 0.1 + }, + "content": { + "cell": "e6c2e441-eb7b-4a4c-9c9c-b88cc9a2527f", + "part": "whole" + }, + "id": "7a689d66-0c9d-4492-928b-f35bfd2ffc4c" + } + } + }, + "2de0c027-7a07-4f7e-8594-a98d36125372": { + "id": "2de0c027-7a07-4f7e-8594-a98d36125372", + "prev": "75e76bd9-24ae-4c42-b6bc-5f58a0550ba8", + "regions": { + "868fd842-e6fb-48b2-9ac5-95e8fe20927e": { + "attrs": { + "height": 0.8, + "width": 0.8, + "x": 0.1, + "y": 0.1 + }, + "content": { + "cell": "0e25dad3-add0-466e-8f71-e771d6ec4500", + "part": "whole" + }, + "id": "868fd842-e6fb-48b2-9ac5-95e8fe20927e" + } + } + }, + "5613e857-5b4e-42e4-9feb-df0440592ca2": { + "id": "5613e857-5b4e-42e4-9feb-df0440592ca2", + "prev": "564dae42-4185-46c1-b156-e503f475e25c", + "regions": { + "17e888b0-050b-406a-a5a3-0d5c1605b8df": { + "attrs": { + "height": 0.8, + "width": 0.8, + "x": 0.1, + "y": 0.1 + }, + "content": { + "cell": "f5bcbcb5-4352-4674-a7b6-c8e576220422", + "part": "whole" + }, + "id": "17e888b0-050b-406a-a5a3-0d5c1605b8df" + } + } + }, + "564dae42-4185-46c1-b156-e503f475e25c": { + "id": "564dae42-4185-46c1-b156-e503f475e25c", + "prev": "ba285213-f645-4314-afd5-0a656fa35631", + "regions": { + "328d4d72-cd9e-4e5b-aaa8-175833f5bfdb": { + "attrs": { + "height": 0.8, + "width": 0.8, + "x": 0.1, + "y": 0.1 + }, + "content": { + "cell": "8a4ac456-6c4b-4249-8662-b1cabfd7cee4", + "part": "whole" + }, + "id": "328d4d72-cd9e-4e5b-aaa8-175833f5bfdb" + } + } + }, + "6ff94ac3-8ded-442e-ae43-aa0a5c14d468": { + "id": "6ff94ac3-8ded-442e-ae43-aa0a5c14d468", + "prev": "27ee4130-d0bb-4287-b8fe-75a7b0ecf178", + "regions": { + "ad759b3a-6080-4356-a9fd-87f2b1b90bc2": { + "attrs": { + "height": 0.8, + "width": 0.8, + "x": 0.1, + "y": 0.1 + }, + "content": { + "cell": "8458de53-35b5-405e-a372-5db5d2e2c2c5", + "part": "whole" + }, + "id": "ad759b3a-6080-4356-a9fd-87f2b1b90bc2" + } + } + }, + "75e76bd9-24ae-4c42-b6bc-5f58a0550ba8": { + "id": "75e76bd9-24ae-4c42-b6bc-5f58a0550ba8", + "prev": "152c5a3b-78f9-4183-bce2-379a4012baf6", + "regions": { + "4afd3b41-071f-44eb-a8f6-9a7f780041c2": { + "attrs": { + "height": 0.8, + "width": 0.8, + "x": 0.1, + "y": 0.1 + }, + "content": { + "cell": "62fdd00c-a006-4f11-b9dc-e2ca072225d7", + "part": "whole" + }, + "id": "4afd3b41-071f-44eb-a8f6-9a7f780041c2" + } + } + }, + "8c46fa2c-d5dc-4ef7-8d99-f504e2c3a4a1": { + "id": "8c46fa2c-d5dc-4ef7-8d99-f504e2c3a4a1", + "prev": "e2f5626f-0d60-47cb-967f-0edababb0329", + "regions": { + "af33776f-ec36-45be-a627-39573a78b1d6": { + "attrs": { + "height": 0.8, + "width": 0.8, + "x": 0.1, + "y": 0.1 + }, + "content": { + "cell": "0d61b4b4-163f-47fe-80f1-092287218273", + "part": "whole" + }, + "id": "af33776f-ec36-45be-a627-39573a78b1d6" + } + } + }, + "ae3f4c01-80dc-4add-889a-05c74f7155a5": { + "id": "ae3f4c01-80dc-4add-889a-05c74f7155a5", + "prev": "6ff94ac3-8ded-442e-ae43-aa0a5c14d468", + "regions": { + "15f00a98-7b04-439d-996d-851b773b060a": { + "attrs": { + "height": 0.8, + "width": 0.8, + "x": 0.1, + "y": 0.1 + }, + "content": { + "cell": "96ca5c44-2cfc-471c-8da7-39870c822e20", + "part": "whole" + }, + "id": "15f00a98-7b04-439d-996d-851b773b060a" + } + } + }, + "ba285213-f645-4314-afd5-0a656fa35631": { + "id": "ba285213-f645-4314-afd5-0a656fa35631", + "prev": "8c46fa2c-d5dc-4ef7-8d99-f504e2c3a4a1", + "regions": { + "6cddb9f2-8e39-4010-8fab-3e70b3a8993f": { + "attrs": { + "height": 0.8, + "width": 0.8, + "x": 0.1, + "y": 0.1 + }, + "content": { + "cell": "b878a4f9-4345-4abb-81f4-5a731c639ab8", + "part": "whole" + }, + "id": "6cddb9f2-8e39-4010-8fab-3e70b3a8993f" + } + } + }, + "cd587236-8a19-444d-8b18-69d782dbf725": { + "id": "cd587236-8a19-444d-8b18-69d782dbf725", + "prev": null, + "regions": { + "ef377bfe-ff45-49db-b471-f79ecb10b580": { + "attrs": { + "height": 0.8, + "width": 0.8, + "x": 0.1, + "y": 0.1 + }, + "content": { + "cell": "dc7a1635-0bbd-4bf7-a07e-7a36f58e258b", + "part": "whole" + }, + "id": "ef377bfe-ff45-49db-b471-f79ecb10b580" + } + } + }, + "e2f5626f-0d60-47cb-967f-0edababb0329": { + "id": "e2f5626f-0d60-47cb-967f-0edababb0329", + "prev": "ae3f4c01-80dc-4add-889a-05c74f7155a5", + "regions": { + "eef49fa0-0f9b-4228-8fb8-79e079bf7682": { + "attrs": { + "height": 0.8, + "width": 0.8, + "x": 0.1, + "y": 0.1 + }, + "content": { + "cell": "9110098b-9675-4d64-adf3-c947073d4c4d", + "part": "whole" + }, + "id": "eef49fa0-0f9b-4228-8fb8-79e079bf7682" + } + } + }, + "f001d476-5814-4664-a722-f04f5d23cd52": { + "id": "f001d476-5814-4664-a722-f04f5d23cd52", + "prev": "cd587236-8a19-444d-8b18-69d782dbf725", + "regions": { + "5a176076-c5a5-4b50-ab2c-9cd0baedad45": { + "attrs": { + "height": 0.8, + "width": 0.8, + "x": 0.1, + "y": 0.1 + }, + "content": { + "cell": "53eee250-b3d0-4262-ad09-e87fb2acf82e", + "part": "whole" + }, + "id": "5a176076-c5a5-4b50-ab2c-9cd0baedad45" + } + } + } + }, + "themes": { + "default": "c6b5d1ad-d691-4000-9f62-de7fc0e83644", + "theme": { + "586a6e7a-f661-4d6c-90d0-1392715bea27": { + "id": "586a6e7a-f661-4d6c-90d0-1392715bea27", + "palette": { + "19cc588f-0593-49c9-9f4b-e4d7cc113b1c": { + "id": "19cc588f-0593-49c9-9f4b-e4d7cc113b1c", + "rgb": [ + 252, + 252, + 252 + ] + }, + "31af15d2-7e15-44c5-ab5e-e04b16a89eff": { + "id": "31af15d2-7e15-44c5-ab5e-e04b16a89eff", + "rgb": [ + 68, + 68, + 68 + ] + }, + "50f92c45-a630-455b-aec3-788680ec7410": { + "id": "50f92c45-a630-455b-aec3-788680ec7410", + "rgb": [ + 155, + 177, + 192 + ] + }, + "c5cc3653-2ee1-402a-aba2-7caae1da4f6c": { + "id": "c5cc3653-2ee1-402a-aba2-7caae1da4f6c", + "rgb": [ + 43, + 126, + 184 + ] + }, + "efa7f048-9acb-414c-8b04-a26811511a21": { + "id": "efa7f048-9acb-414c-8b04-a26811511a21", + "rgb": [ + 25.118061674008803, + 73.60176211453744, + 107.4819383259912 + ] + } + }, + "rules": { + "blockquote": { + "color": "50f92c45-a630-455b-aec3-788680ec7410" + }, + "code": { + "font-family": "Anonymous Pro" + }, + "h1": { + "color": "c5cc3653-2ee1-402a-aba2-7caae1da4f6c", + "font-family": "Lato", + "font-size": 8 + }, + "h2": { + "color": "c5cc3653-2ee1-402a-aba2-7caae1da4f6c", + "font-family": "Lato", + "font-size": 6 + }, + "h3": { + "color": "50f92c45-a630-455b-aec3-788680ec7410", + "font-family": "Lato", + "font-size": 5.5 + }, + "h4": { + "color": "c5cc3653-2ee1-402a-aba2-7caae1da4f6c", + "font-family": "Lato", + "font-size": 5 + }, + "h5": { + "font-family": "Lato" + }, + "h6": { + "font-family": "Lato" + }, + "h7": { + "font-family": "Lato" + }, + "pre": { + "font-family": "Anonymous Pro", + "font-size": 4 + } + }, + "text-base": { + "font-family": "Merriweather", + "font-size": 4 + } + }, + "c6b5d1ad-d691-4000-9f62-de7fc0e83644": { + "backgrounds": { + "dc7afa04-bf90-40b1-82a5-726e3cff5267": { + "background-color": "31af15d2-7e15-44c5-ab5e-e04b16a89eff", + "id": "dc7afa04-bf90-40b1-82a5-726e3cff5267" + } + }, + "id": "c6b5d1ad-d691-4000-9f62-de7fc0e83644", + "palette": { + "19cc588f-0593-49c9-9f4b-e4d7cc113b1c": { + "id": "19cc588f-0593-49c9-9f4b-e4d7cc113b1c", + "rgb": [ + 252, + 252, + 252 + ] + }, + "31af15d2-7e15-44c5-ab5e-e04b16a89eff": { + "id": "31af15d2-7e15-44c5-ab5e-e04b16a89eff", + "rgb": [ + 68, + 68, + 68 + ] + }, + "50f92c45-a630-455b-aec3-788680ec7410": { + "id": "50f92c45-a630-455b-aec3-788680ec7410", + "rgb": [ + 197, + 226, + 245 + ] + }, + "c5cc3653-2ee1-402a-aba2-7caae1da4f6c": { + "id": "c5cc3653-2ee1-402a-aba2-7caae1da4f6c", + "rgb": [ + 43, + 126, + 184 + ] + }, + "efa7f048-9acb-414c-8b04-a26811511a21": { + "id": "efa7f048-9acb-414c-8b04-a26811511a21", + "rgb": [ + 25.118061674008803, + 73.60176211453744, + 107.4819383259912 + ] + } + }, + "rules": { + "a": { + "color": "19cc588f-0593-49c9-9f4b-e4d7cc113b1c" + }, + "blockquote": { + "color": "50f92c45-a630-455b-aec3-788680ec7410", + "font-size": 3 + }, + "code": { + "font-family": "Anonymous Pro" + }, + "h1": { + "color": "19cc588f-0593-49c9-9f4b-e4d7cc113b1c", + "font-family": "Merriweather", + "font-size": 8 + }, + "h2": { + "color": "19cc588f-0593-49c9-9f4b-e4d7cc113b1c", + "font-family": "Merriweather", + "font-size": 6 + }, + "h3": { + "color": "50f92c45-a630-455b-aec3-788680ec7410", + "font-family": "Lato", + "font-size": 5.5 + }, + "h4": { + "color": "c5cc3653-2ee1-402a-aba2-7caae1da4f6c", + "font-family": "Lato", + "font-size": 5 + }, + "h5": { + "font-family": "Lato" + }, + "h6": { + "font-family": "Lato" + }, + "h7": { + "font-family": "Lato" + }, + "li": { + "color": "50f92c45-a630-455b-aec3-788680ec7410", + "font-size": 3.25 + }, + "pre": { + "font-family": "Anonymous Pro", + "font-size": 4 + } + }, + "text-base": { + "color": "19cc588f-0593-49c9-9f4b-e4d7cc113b1c", + "font-family": "Lato", + "font-size": 4 + } + } + } + } + } + }, + "nbformat": 4, + "nbformat_minor": 1 +}