From 77669161e0100a313876a4b4e4d32935ae871bf1 Mon Sep 17 00:00:00 2001 From: nrius Date: Sat, 16 Jan 2021 13:55:51 +0100 Subject: [PATCH 1/3] adding lab --- your-code/main.ipynb | 215 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 197 insertions(+), 18 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 01257d4..b720e69 100755 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -21,20 +21,90 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 32, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "TypeError", + "evalue": "() missing 1 required positional argument: 'y'", + "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[0mnum\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m4\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mlist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmap\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mlambda\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mx\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnum\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m: () missing 1 required positional argument: 'y'" + ] + } + ], "source": [ + "num=[4,3]\n", + "list(map(lambda x,y: x + y, num))" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "<>:13: SyntaxWarning: 'int' object is not subscriptable; perhaps you missed a comma?\n", + "<>:13: SyntaxWarning: 'int' object is not subscriptable; perhaps you missed a comma?\n", + ":13: SyntaxWarning: 'int' object is not subscriptable; perhaps you missed a comma?\n", + " lmbda=(lambda n:n+1[1,2])\n" + ] + }, + { + "ename": "TypeError", + "evalue": "'function' object is not iterable", + "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 15\u001b[0m \u001b[0mlst\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 16\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 17\u001b[0;31m \u001b[0mmodify_list\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlmbda\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mlst\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m\u001b[0m in \u001b[0;36mmodify_list\u001b[0;34m(lst, lmbda)\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;31m# your code here\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0;31m#use map\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 8\u001b[0;31m \u001b[0mx\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmap\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlmbda\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mlst\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 9\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mTypeError\u001b[0m: 'function' object is not iterable" + ] + } + ], + "source": [ + "#failed attempt\n", "def modify_list(lst, lmbda):\n", " \"\"\"\n", " Input: list and lambda expression\n", " Output: the transformed list\n", " \"\"\"\n", - " \n", " # your code here\n", - " " + " #use map\n", + " x=list(map(lmbda,lst))\n", + " return x\n", + "\n", + "num=[4,3,2]\n", + "\n", + "lmbda=(lambda n:n+1[1,2]) \n", + " #(lambda x: x + 10, [1,2])\n", + "lst=[1,2,3]\n", + "\n", + "modify_list(lmbda,lst)" ] }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " at 0x7fc0689c8790>\n" + ] + } + ], + "source": [] + }, { "cell_type": "markdown", "metadata": {}, @@ -46,11 +116,26 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "303.15" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "# your code here\n", + "temp=(30)\n", + "f=(lambda x: x +273.15)\n", + "f(temp)\n", + "#list(map(lambda x: x + 10, [1,2]))" ] }, { @@ -62,13 +147,26 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 18, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[285.15, 296.15, 311.15, 218.14999999999998, 297.15]" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "temps = [12, 23, 38, -55, 24]\n", "\n", - "# your code here" + "# your code here\n", + "\n", + "list(map(lambda x: x + 273.15, temps))" ] }, { @@ -82,11 +180,34 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "# your code here\n", + "\n", + "\n", + "mod = lambda x, y: 1 if x%y == 0 else 0" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mod(1,4)\n" ] }, { @@ -100,7 +221,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 29, "metadata": {}, "outputs": [], "source": [ @@ -111,7 +232,10 @@ " divisible by another number (to be passed later) and zero otherwise.\n", " \"\"\"\n", " \n", - " # your code here" + " # your code here\n", + "\n", + " mod = lambda x, y: 1 if x%y == 0 else 0\n", + " return mod\n" ] }, { @@ -123,11 +247,24 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 31, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "TypeError", + "evalue": "'function' object is not iterable", + "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[0;31m# your code here\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mlist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdivisor\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m5\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m: 'function' object is not iterable" + ] + } + ], "source": [ - "# your code here" + "# your code here\n", + "(divisor(5)" ] }, { @@ -269,7 +406,49 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.8.5" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": true, + "sideBar": true, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": true, + "toc_window_display": false + }, + "varInspector": { + "cols": { + "lenName": 16, + "lenType": 16, + "lenVar": 40 + }, + "kernels_config": { + "python": { + "delete_cmd_postfix": "", + "delete_cmd_prefix": "del ", + "library": "var_list.py", + "varRefreshCmd": "print(var_dic_list())" + }, + "r": { + "delete_cmd_postfix": ") ", + "delete_cmd_prefix": "rm(", + "library": "var_list.r", + "varRefreshCmd": "cat(var_dic_list()) " + } + }, + "types_to_exclude": [ + "module", + "function", + "builtin_function_or_method", + "instance", + "_Feature" + ], + "window_display": false } }, "nbformat": 4, From c5f8c83535d45d1c161c1c0ab39e8b015448ea46 Mon Sep 17 00:00:00 2001 From: nrius Date: Sat, 16 Jan 2021 16:43:06 +0100 Subject: [PATCH 2/3] adding lab --- your-code/main.ipynb | 68 ++++++++++++++------------------------------ 1 file changed, 22 insertions(+), 46 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index b720e69..abfa835 100755 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -21,56 +21,29 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 44, "metadata": {}, "outputs": [ { - "ename": "TypeError", - "evalue": "() missing 1 required positional argument: 'y'", - "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[0mnum\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m4\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mlist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmap\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mlambda\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mx\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnum\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m: () missing 1 required positional argument: 'y'" - ] - } - ], - "source": [ - "num=[4,3]\n", - "list(map(lambda x,y: x + y, num))" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "name": "stderr", + "name": "stdout", "output_type": "stream", "text": [ - "<>:13: SyntaxWarning: 'int' object is not subscriptable; perhaps you missed a comma?\n", - "<>:13: SyntaxWarning: 'int' object is not subscriptable; perhaps you missed a comma?\n", - ":13: SyntaxWarning: 'int' object is not subscriptable; perhaps you missed a comma?\n", - " lmbda=(lambda n:n+1[1,2])\n" + "5\n" ] }, { - "ename": "TypeError", - "evalue": "'function' object is not iterable", - "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 15\u001b[0m \u001b[0mlst\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 16\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 17\u001b[0;31m \u001b[0mmodify_list\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlmbda\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mlst\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;32m\u001b[0m in \u001b[0;36mmodify_list\u001b[0;34m(lst, lmbda)\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;31m# your code here\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0;31m#use map\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 8\u001b[0;31m \u001b[0mx\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmap\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlmbda\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mlst\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 9\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mTypeError\u001b[0m: 'function' object is not iterable" - ] + "data": { + "text/plain": [ + "[2, 3, 4]" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "#failed attempt\n", + "\n", "def modify_list(lst, lmbda):\n", " \"\"\"\n", " Input: list and lambda expression\n", @@ -81,13 +54,16 @@ " x=list(map(lmbda,lst))\n", " return x\n", "\n", - "num=[4,3,2]\n", + "num=[4]\n", + "\n", + "lmbda_1=(lambda n:n+1) \n", + "print(lmbda(4)) \n", + "lst_1=[1,2,3]\n", "\n", - "lmbda=(lambda n:n+1[1,2]) \n", - " #(lambda x: x + 10, [1,2])\n", - "lst=[1,2,3]\n", "\n", - "modify_list(lmbda,lst)" + "list(map((lambda n:n+1),lst))\n", + "\n", + "#modify_list(lmbda_1,lst_1)" ] }, { @@ -116,7 +92,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 33, "metadata": {}, "outputs": [ { @@ -125,7 +101,7 @@ "303.15" ] }, - "execution_count": 11, + "execution_count": 33, "metadata": {}, "output_type": "execute_result" } From 418e063ec91d733654ffe809b9bba3367ef32b7e Mon Sep 17 00:00:00 2001 From: nrius Date: Sat, 16 Jan 2021 17:08:16 +0100 Subject: [PATCH 3/3] rectifying labs --- your-code/main.ipynb | 83 ++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index abfa835..9fe1f60 100755 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -66,21 +66,6 @@ "#modify_list(lmbda_1,lst_1)" ] }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " at 0x7fc0689c8790>\n" - ] - } - ], - "source": [] - }, { "cell_type": "markdown", "metadata": {}, @@ -110,8 +95,7 @@ "# your code here\n", "temp=(30)\n", "f=(lambda x: x +273.15)\n", - "f(temp)\n", - "#list(map(lambda x: x + 10, [1,2]))" + "f(temp)\n" ] }, { @@ -156,19 +140,34 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 49, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# your code here\n", + "# lambda : if else \n", + "\n", + "#lambda x : True if (x > 10 and x < 20) else False\n", "\n", + "mod = lambda x, y: 1 if x%y == 0 else 0\n", "\n", - "mod = lambda x, y: 1 if x%y == 0 else 0" + "mod(2,1)\n" ] }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 51, "metadata": {}, "outputs": [ { @@ -177,13 +176,13 @@ "0" ] }, - "execution_count": 24, + "execution_count": 51, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "mod(1,4)\n" + "mod(8,5)\n" ] }, { @@ -197,7 +196,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 52, "metadata": {}, "outputs": [], "source": [ @@ -210,7 +209,7 @@ " \n", " # your code here\n", "\n", - " mod = lambda x, y: 1 if x%y == 0 else 0\n", + " mod = lambda b, x: 1 if b%x == 0 else 0\n", " return mod\n" ] }, @@ -223,24 +222,12 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 57, "metadata": {}, - "outputs": [ - { - "ename": "TypeError", - "evalue": "'function' object is not iterable", - "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[0;31m# your code here\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mlist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdivisor\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m5\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m: 'function' object is not iterable" - ] - } - ], + "outputs": [], "source": [ "# your code here\n", - "(divisor(5)" + "divisible5=divisor(5)" ] }, { @@ -252,9 +239,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 58, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "TypeError", + "evalue": "() missing 1 required positional argument: 'y'", + "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[0;32m----> 1\u001b[0;31m \u001b[0mdivisible5\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m: () missing 1 required positional argument: 'y'" + ] + } + ], "source": [ "divisible5(10)" ]