{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "

cs1001.py , Tel Aviv University, Fall 2017-2018

\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Recitation 2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We tested if a positive integer (or a range of integers) satisfies the Collatz conjecture (using \"while\" and \"for\" loops). \n", "We discussed the basics of lists, the efficiency of list operations and how to efficiently concatenate a list to another. We also demonstrated list comprehension. \n", "Finally, we discussed functions, short circuit evaluation and analyzed the efficiency of the functions we saw.\n", "\n", "#### Takeaways:\n", "\n", "
    \n", "
  1. Lists can be a highly modular and useful data structure. Make sure that you understand their functionality and also their limits (figuratively and literally).
  2. \n", "
  3. Avoid using the + operator for extending a given list. Use += or list.extend() instead.\n", "
  4. Functions can be used in one another (max2 in max3_v3) and can be composed together.
  5. \n", "
  6. When analyzing a function's performance, think about the input that will cause the largest amount of work and then measure how many operations the function does.
  7. \n", "
  8. Using short circuit evaluation, if e.g. you have a long \"and\" condition, place the part that is most easy to compute first since if it is false, all other parts of the condition will not be computed.
  9. \n", "
\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Code for printing several outputs in one cell (not part of the recitation):" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "from IPython.core.interactiveshell import InteractiveShell\n", "InteractiveShell.ast_node_interactivity = \"all\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Collatz Conjecture" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Check conjecture for a single number:" ] }, { "cell_type": "code", "execution_count": 61, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Enter a positive integer to apply Collatz algorithm: 7\n", "7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1\n", "7 is OK!\n" ] } ], "source": [ "orig_num = int(input(\"Enter a positive integer to apply Collatz algorithm: \"))\n", "num = orig_num\n", "\n", "while num > 1:\n", " print(num, end=\" \")\n", " if num%2 == 0:\n", " num = num//2\n", " else:\n", " num = 3*num+1\n", "\n", "print(num)\n", "print( orig_num, \"is OK!\")\n", "\n", "\n", " \n", " \n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Check conjecture for a range of numbers:" ] }, { "cell_type": "code", "execution_count": 62, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Check Collatz algorithm for 1 ... 10\n", "1\n", "1 is OK!\n", "2 1\n", "2 is OK!\n", "3 10 5 16 8 4 2 1\n", "3 is OK!\n", "4 2 1\n", "4 is OK!\n", "5 16 8 4 2 1\n", "5 is OK!\n", "6 3 10 5 16 8 4 2 1\n", "6 is OK!\n", "7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1\n", "7 is OK!\n", "8 4 2 1\n", "8 is OK!\n", "9 28 14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1\n", "9 is OK!\n", "10 5 16 8 4 2 1\n", "10 is OK!\n" ] } ], "source": [ "limit = int(input(\"Check Collatz algorithm for 1 ... \"))\n", "\n", "orig_num =1\n", "while orig_num <= limit:\n", " num = orig_num\n", "\n", " while num > 1:\n", " print(num, end=\" \")\n", " if num%2 == 0:\n", " num = num//2\n", " else:\n", " num = 3*num+1\n", "\n", " print(num)\n", " print( orig_num, \"is OK!\")\n", " \n", " orig_num += 1\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### range examples" ] }, { "cell_type": "code", "execution_count": 63, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n", "9\n" ] } ], "source": [ "for i in range(10):\n", " print(i)\n", " " ] }, { "cell_type": "code", "execution_count": 64, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n", "3\n", "5\n" ] } ], "source": [ "for i in range(1, 7, 2):\n", " print(i)\n" ] }, { "cell_type": "code", "execution_count": 71, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "7\n", "5\n", "3\n" ] } ], "source": [ "for i in range(7, 1, -2):\n", " print(i)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Check conjecture for a range of numbers (using \"for\")" ] }, { "cell_type": "code", "execution_count": 72, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Check Collatz algorithm for 1 ... 4\n", "1\n", "1 is OK!\n", "2 1\n", "2 is OK!\n", "3 10 5 16 8 4 2 1\n", "3 is OK!\n", "4 2 1\n", "4 is OK!\n" ] } ], "source": [ "limit = int(input(\"Check Collatz algorithm for 1 ... \"))\n", "\n", "\n", "for orig_num in range(1, limit+1):\n", " num = orig_num\n", "\n", " while num > 1:\n", " print(num, end=\" \")\n", " if num%2 == 0:\n", " num = num//2\n", " else:\n", " num = 3*num+1\n", "\n", " print(num)\n", " print( orig_num, \"is OK!\")\n", " \n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Lists - Basics" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "code", "execution_count": 78, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "8" ] }, "execution_count": 78, "metadata": {}, "output_type": "execute_result" }, { "data": { "text/plain": [ "'name'" ] }, "execution_count": 78, "metadata": {}, "output_type": "execute_result" }, { "data": { "text/plain": [ "" ] }, "execution_count": 78, "metadata": {}, "output_type": "execute_result" }, { "name": "stdout", "output_type": "stream", "text": [ "hello\n" ] }, { "data": { "text/plain": [ "[3.14, 2.5]" ] }, "execution_count": 78, "metadata": {}, "output_type": "execute_result" }, { "data": { "text/plain": [ "3.14" ] }, "execution_count": 78, "metadata": {}, "output_type": "execute_result" }, { "data": { "text/plain": [ "[True, 1000, 2, 3, 'name', , True, [3.14, 2.5]]" ] }, "execution_count": 78, "metadata": {}, "output_type": "execute_result" }, { "ename": "IndexError", "evalue": "list assignment index out of range", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[0mlst\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m1000\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[0mlst\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 12\u001b[1;33m \u001b[0mlst\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m8\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m40\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 13\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;31mIndexError\u001b[0m: list assignment index out of range" ] } ], "source": [ "X = 10\n", "lst = [x,1,2,3,\"name\", print, True, [3.14, 2.5]]\n", "len(lst)\n", "lst[4]\n", "lst[5]\n", "lst[5](\"hello\")\n", "#lst[100]\n", "lst[-1]\n", "lst[-1][0]\n", "lst[1] = 1000\n", "lst\n", "lst[8] = 40\n", "\n" ] }, { "cell_type": "code", "execution_count": 79, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 79, "metadata": {}, "output_type": "execute_result" }, { "ename": "IndexError", "evalue": "list index out of range", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mempty_lst\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mempty_lst\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mempty_lst\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[1;31mIndexError\u001b[0m: list index out of range" ] } ], "source": [ "empty_lst = []\n", "len(empty_lst)\n", "empty_lst[0]" ] }, { "cell_type": "code", "execution_count": 80, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[3, , [3.14, 2.5]]" ] }, "execution_count": 80, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lst = [x,1,2,3,\"name\", print, True, [3.14, 2.5]]\n", "lst[3: 8: 2]\n", "\n" ] }, { "cell_type": "code", "execution_count": 92, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 2, 3, 10, 20, 30]" ] }, "execution_count": 92, "metadata": {}, "output_type": "execute_result" }, { "data": { "text/plain": [ "[1, 2, 3]" ] }, "execution_count": 92, "metadata": {}, "output_type": "execute_result" }, { "data": { "text/plain": [ "[10, 20, 30]" ] }, "execution_count": 92, "metadata": {}, "output_type": "execute_result" }, { "name": "stdout", "output_type": "stream", "text": [ "Bad coding:\n" ] }, { "data": { "text/plain": [ "[1, 2, 3, 10, 20, 30]" ] }, "execution_count": 92, "metadata": {}, "output_type": "execute_result" }, { "name": "stdout", "output_type": "stream", "text": [ "Good coding:\n" ] }, { "data": { "text/plain": [ "[1, 2, 3, 10, 20, 30]" ] }, "execution_count": 92, "metadata": {}, "output_type": "execute_result" }, { "data": { "text/plain": [ "[1, 2, 3, 10, 20, 30, 10]" ] }, "execution_count": 92, "metadata": {}, "output_type": "execute_result" }, { "data": { "text/plain": [ "[1, 2, 3, 10, 20, 30, 10, [10, 20, 30]]" ] }, "execution_count": 92, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lst1 = [1,2,3]\n", "lst2 = [10,20,30]\n", "\n", "lst_new = lst1 + lst2\n", "lst_new\n", "lst1\n", "lst2\n", "\n", "print(\"Bad coding:\")\n", "lst1 = lst1 + lst2\n", "lst1\n", "\n", "print(\"Good coding:\")\n", "lst1 = [1,2,3]\n", "lst2 = [10,20,30]\n", "lst1.extend(lst2)\n", "lst1\n", "lst1.append(10)\n", "lst1\n", "lst1.append(lst2)\n", "lst1\n", "\n", "lst1 = [1,2,3]\n", "lst2 = [10,20,30]\n", "lst1 += lst2 #invokes extend!!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Common List functions" ] }, { "cell_type": "code", "execution_count": 85, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-24.5" ] }, "execution_count": 85, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lst = [10, -40.5, 6]\n", "sum(lst)" ] }, { "cell_type": "code", "execution_count": 86, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[-40.5, 6, 10]" ] }, "execution_count": 86, "metadata": {}, "output_type": "execute_result" }, { "data": { "text/plain": [ "[10, -40.5, 6]" ] }, "execution_count": 86, "metadata": {}, "output_type": "execute_result" }, { "data": { "text/plain": [ "[-40.5, 6, 10]" ] }, "execution_count": 86, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lst = [10, -40.5, 6]\n", "slst = sorted(lst)\n", "slst\n", "lst\n", "\n", "lst.sort()\n", "lst" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Iterating over lists" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "Using while loop" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n", "2\n", "3\n", "4\n", "hi\n", "bye\n", "100\n" ] } ], "source": [ "lst = [1,2,3,4,\"hi\", \"bye\", 100]\n", "i = 0\n", "while i < len(lst):\n", " print(lst[i])\n", " i += 1" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "Using for loop with range" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n", "2\n", "3\n", "4\n", "hi\n", "bye\n", "100\n" ] } ], "source": [ "lst = [1,2,3,4,\"hi\", \"bye\", 100]\n", "for i in range(len(lst)):\n", " print(lst[i])\n", " " ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "Using for loop over elements" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n", "2\n", "3\n", "4\n", "hi\n", "bye\n", "100\n" ] } ], "source": [ "lst = [1,2,3,4,\"hi\", \"bye\", 100]\n", "for item in lst:\n", " print(item)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercise: given grades, how many are there above average?" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "#### solution 1: using loops" ] }, { "cell_type": "code", "execution_count": 87, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "How many grades? 4\n", "enter a grade: 10\n", "enter a grade: 78\n", "enter a grade: 60.5\n", "enter a grade: 92\n", "3 grades are above the average 60.125\n" ] } ], "source": [ "count = int(input(\"How many grades? \"))\n", "above = 0\n", "\n", "grades = []\n", "for i in range(count):\n", " grade = float(input(\"enter a grade: \"))\n", " #grades[i] = grade #wrong\n", " #grades.append(grade)\n", " #grades.extend([grade])\n", " grades += [grade] #invokes extend\n", " #grades = grades + [grade] #bad coding!\n", " \n", "s = sum(grades)\n", "avg = s/count\n", "\n", "for grade in grades:\n", " if grade > avg:\n", " above += 1\n", "\n", "print(above, \"grades are above the average\", avg)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### list comprehension example:" ] }, { "cell_type": "code", "execution_count": 89, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0, 3, 6, 9]" ] }, "execution_count": 89, "metadata": {}, "output_type": "execute_result" }, { "data": { "text/plain": [ "[0, 9, 36, 81]" ] }, "execution_count": 89, "metadata": {}, "output_type": "execute_result" }, { "data": { "text/plain": [ "['!', '!', '!', '!']" ] }, "execution_count": 89, "metadata": {}, "output_type": "execute_result" }, { "data": { "text/plain": [ "[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]" ] }, "execution_count": 89, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lst = [0,1,2,3,4,5,6,7,8,9]\n", "lst1 = [x for x in lst if x%3==0]\n", "lst1\n", "lst2 = [x**2 for x in lst if x%3==0]\n", "lst2\n", "lst3 = [\"!\" for x in lst if 2*x > 10]\n", "lst3\n", "lst4 = [1 for x in lst]\n", "lst4\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Solution 2: using list comprehension" ] }, { "cell_type": "code", "execution_count": 90, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "How many grades? 3\n", "enter a grade: 100\n", "enter a grade: 50\n", "enter a grade: 20\n", "1 grades are above the average 56.666666666666664\n" ] } ], "source": [ "count = int(input(\"How many grades? \"))\n", "above = 0\n", "\n", "grades = []\n", "#try to replace this loop by list comprehension exp\n", "for i in range(count):\n", " grade = float(input(\"enter a grade: \"))\n", " #grades[i] = grade #wrong\n", " #grades.append(grade)\n", " #grades.extend([grade])\n", " grades += [grade] #invokes extend\n", " #grades = grades + [grade] #bad coding!\n", " \n", "s = sum(grades)\n", "avg = s/count\n", "\n", "\n", "above = len([grade for grade in grades if grade > avg])\n", "\n", "print(above, \"grades are above the average\", avg)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Functions: max2, max3" ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "30" ] }, "execution_count": 52, "metadata": {}, "output_type": "execute_result" }, { "ename": "TypeError", "evalue": "max2() missing 1 required positional argument: 'b'", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[0mx\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mmax2\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m10\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m30\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 12\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 13\u001b[1;33m \u001b[0my\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mmax2\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m10\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[1;31mTypeError\u001b[0m: max2() missing 1 required positional argument: 'b'" ] } ], "source": [ "def max2(a,b):\n", " '''\n", " max2(float,float) ---> float\n", " return the maximum od a and b\n", " '''\n", " if a>=b:\n", " return a\n", " #else:\n", " # return b\n", " return b\n", "\n", "x = max2(10,30)\n", "x\n", "y = max2(10)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### max3" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### at most 4 comparisons" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def max3_v1(a,b,c):\n", " if a>=b and a>=c:\n", " return a\n", " elif b>=a and b>=c:\n", " return b\n", " else:\n", " return c" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### at most 2 comparisons" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def max3_v2(a,b,c):\n", " if a>=b:\n", " if a>=c:\n", " return a\n", " else:\n", " return c\n", " else:\n", " if b>=c:\n", " return b\n", " else:\n", " return c" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### at most 2 comparisons" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "def max3_v3(a,b,c):\n", "## max_ab = max2(a,b)\n", "## total_max = max2(max_ab,c)\n", "## return total_max\n", " return max2(max2(a,b), c)\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Short circuit evaluation" ] }, { "cell_type": "code", "execution_count": 91, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 91, "metadata": {}, "output_type": "execute_result" }, { "ename": "ZeroDivisionError", "evalue": "division by zero", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mx\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mTrue\u001b[0m \u001b[1;32mor\u001b[0m \u001b[1;36m3\u001b[0m\u001b[1;33m/\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mx\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m3\u001b[0m\u001b[1;33m/\u001b[0m\u001b[1;36m0\u001b[0m \u001b[1;32mor\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 4\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;31mZeroDivisionError\u001b[0m: division by zero" ] } ], "source": [ "x = True or 3/0\n", "x\n", "x = 3/0 or True\n", "x\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.6.2" } }, "nbformat": 4, "nbformat_minor": 1 }