From 7971707820cb48318388096fe58fd55ace54b5de Mon Sep 17 00:00:00 2001 From: Nacho Rus Date: Wed, 24 Mar 2021 18:09:12 +0100 Subject: [PATCH] Finished --- your-code/main.ipynb | 267 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 227 insertions(+), 40 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 01257d4..6528637 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -22,7 +22,12 @@ { "cell_type": "code", "execution_count": 1, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2021-03-24T17:08:23.403284Z", + "start_time": "2021-03-24T17:08:23.393500Z" + } + }, "outputs": [], "source": [ "def modify_list(lst, lmbda):\n", @@ -31,7 +36,8 @@ " Output: the transformed list\n", " \"\"\"\n", " \n", - " # your code here\n", + " result = list(map(lmbda,lst))\n", + " return result\n", " " ] }, @@ -46,11 +52,16 @@ }, { "cell_type": "code", - "execution_count": 3, - "metadata": {}, + "execution_count": 2, + "metadata": { + "ExecuteTime": { + "end_time": "2021-03-24T17:08:24.480168Z", + "start_time": "2021-03-24T17:08:24.471725Z" + } + }, "outputs": [], "source": [ - "# your code here" + "lam = lambda a: 273.15 + a" ] }, { @@ -62,13 +73,31 @@ }, { "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], + "execution_count": 3, + "metadata": { + "ExecuteTime": { + "end_time": "2021-03-24T17:08:25.405547Z", + "start_time": "2021-03-24T17:08:25.378125Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[285.15, 296.15, 311.15, 218.14999999999998, 297.15]" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "temps = [12, 23, 38, -55, 24]\n", "\n", - "# your code here" + "# your code here\n", + "\n", + "modify_list(temps,lam)" ] }, { @@ -82,11 +111,18 @@ }, { "cell_type": "code", - "execution_count": 5, - "metadata": {}, + "execution_count": 4, + "metadata": { + "ExecuteTime": { + "end_time": "2021-03-24T17:08:26.348401Z", + "start_time": "2021-03-24T17:08:26.340118Z" + } + }, "outputs": [], "source": [ - "# your code here" + "# your code here\n", + "\n", + "mod = lambda x,y: 1 if (x%y == 0) else 0" ] }, { @@ -100,8 +136,13 @@ }, { "cell_type": "code", - "execution_count": 6, - "metadata": {}, + "execution_count": 5, + "metadata": { + "ExecuteTime": { + "end_time": "2021-03-24T17:08:27.121096Z", + "start_time": "2021-03-24T17:08:27.116591Z" + } + }, "outputs": [], "source": [ "def divisor(b):\n", @@ -111,7 +152,9 @@ " divisible by another number (to be passed later) and zero otherwise.\n", " \"\"\"\n", " \n", - " # your code here" + " # your code here\n", + " \n", + " return lambda y: 1 if (y%b == 0) else 0" ] }, { @@ -123,11 +166,17 @@ }, { "cell_type": "code", - "execution_count": 7, - "metadata": {}, + "execution_count": 6, + "metadata": { + "ExecuteTime": { + "end_time": "2021-03-24T17:08:27.898771Z", + "start_time": "2021-03-24T17:08:27.889866Z" + } + }, "outputs": [], "source": [ - "# your code here" + "# your code here\n", + "divisible5 = divisor(5)" ] }, { @@ -139,18 +188,50 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 7, + "metadata": { + "ExecuteTime": { + "end_time": "2021-03-24T17:08:28.631631Z", + "start_time": "2021-03-24T17:08:28.622940Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "divisible5(10)" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 8, + "metadata": { + "ExecuteTime": { + "end_time": "2021-03-24T17:08:28.969713Z", + "start_time": "2021-03-24T17:08:28.960979Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "divisible5(8)" ] @@ -168,8 +249,13 @@ }, { "cell_type": "code", - "execution_count": 10, - "metadata": {}, + "execution_count": 9, + "metadata": { + "ExecuteTime": { + "end_time": "2021-03-24T17:08:29.674529Z", + "start_time": "2021-03-24T17:08:29.664318Z" + } + }, "outputs": [ { "data": { @@ -177,7 +263,7 @@ "[(1,), (2,), (3,), (4,), (5,)]" ] }, - "execution_count": 10, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -199,14 +285,34 @@ }, { "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [], + "execution_count": 10, + "metadata": { + "ExecuteTime": { + "end_time": "2021-03-24T17:08:30.566525Z", + "start_time": "2021-03-24T17:08:30.547540Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[('Green', 'eggs'),\n", + " ('cheese', 'cheese'),\n", + " ('English', 'cucumber'),\n", + " ('tomato', 'tomato')]" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "list1 = ['Green', 'cheese', 'English', 'tomato']\n", "list2 = ['eggs', 'cheese', 'cucumber', 'tomato']\n", "\n", - "# your code here" + "# your code here\n", + "[x for x in zip(list1,list2)]" ] }, { @@ -222,14 +328,31 @@ }, { "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], + "execution_count": 11, + "metadata": { + "ExecuteTime": { + "end_time": "2021-03-24T17:08:33.910475Z", + "start_time": "2021-03-24T17:08:33.901366Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[('Engineering', 'Lab'), ('Computer Science', 'Homework'), ('Mathematics', 'Module'), ('Political Science', 'Essay')]\n" + ] + } + ], "source": [ "list1 = ['Engineering', 'Computer Science', 'Political Science', 'Mathematics']\n", "list2 = ['Lab', 'Homework', 'Essay', 'Module']\n", "\n", - "# your code here" + "# your code here\n", + "list3 = [x for x in zip(list1,list2)]\n", + "lam = lambda lst: lst[1][1]\n", + "list3.sort(key=lam)\n", + "print(list3)" ] }, { @@ -243,13 +366,30 @@ }, { "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [], + "execution_count": 12, + "metadata": { + "ExecuteTime": { + "end_time": "2021-03-24T17:08:34.920152Z", + "start_time": "2021-03-24T17:08:34.912064Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[('Toyota', 1995), ('Honda', 1997), ('Audi', 2001), ('BMW', 2005)]\n" + ] + } + ], "source": [ "d = {'Honda': 1997, 'Toyota': 1995, 'Audi': 2001, 'BMW': 2005}\n", "\n", - "# your code here" + "# your code here\n", + "list3 = [x for x in zip(d.keys(),d.values())]\n", + "lam = lambda lst: lst[1]\n", + "list3.sort(key=lam)\n", + "print(list3)" ] } ], @@ -269,7 +409,54 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.8.2" + }, + "latex_envs": { + "LaTeX_envs_menu_present": true, + "autoclose": false, + "autocomplete": true, + "bibliofile": "biblio.bib", + "cite_by": "apalike", + "current_citInitial": 1, + "eqLabelWithNumbers": true, + "eqNumInitial": 1, + "hotkeys": { + "equation": "Ctrl-E", + "itemize": "Ctrl-I" + }, + "labels_anchors": false, + "latex_user_defs": false, + "report_style_numbering": false, + "user_envs_cfg": 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": true } }, "nbformat": 4,