diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 01257d4..e9f45b8 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -21,17 +21,14 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "def modify_list(lst, lmbda):\n", - " \"\"\"\n", - " Input: list and lambda expression\n", - " Output: the transformed list\n", - " \"\"\"\n", " \n", - " # your code here\n", + " \n", + " return list(map(lmbda , lst))\n", " " ] }, @@ -46,11 +43,24 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "(x)>" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "to_kelvin = lambda x : x + 273.15\n", + "\n", + "to_kelvin" ] }, { @@ -62,13 +72,31 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ - "temps = [12, 23, 38, -55, 24]\n", - "\n", - "# your code here" + "temps = [12, 23, 38, -55, 24]" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[285.15, 296.15, 311.15, 218.14999999999998, 297.15]" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "modify_list (temps,to_kelvin)" ] }, { @@ -84,9 +112,22 @@ "cell_type": "code", "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "mod = lambda a,b : 1 if a % b == 0 else 0\n", + "\n", + "mod(8,4)\n" ] }, { @@ -100,7 +141,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -110,6 +151,10 @@ " Output: a function that returns 1 if the number is \n", " divisible by another number (to be passed later) and zero otherwise.\n", " \"\"\"\n", + " return lambda a : mod(a,b)\n", + "\n", + "\n", + "\n", " \n", " # your code here" ] @@ -123,11 +168,11 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "divisible5 = divisor(5)" ] }, { @@ -139,18 +184,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "divisible5(10)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "divisible5(8)" ] @@ -159,7 +226,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Bonus Challenge - Using Lambda Expressions in List Comprehensions\n", + "# Bonus Challenge - Using Lambda Expressions in List Comprehensions\n", "\n", "In the following challenge, we will combine two lists using a lambda expression in a list comprehension. \n", "\n", @@ -213,7 +280,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Bonus Challenge - Using Lambda Expressions as Arguments\n", + "# Bonus Challenge - Using Lambda Expressions as Arguments\n", "\n", "#### In this challenge, we will zip together two lists and sort by the resulting tuple.\n", "\n", @@ -226,6 +293,9 @@ "metadata": {}, "outputs": [], "source": [ + "# BONUS, NO NEEDED TO DO IT\n", + "\n", + "\n", "list1 = ['Engineering', 'Computer Science', 'Political Science', 'Mathematics']\n", "list2 = ['Lab', 'Homework', 'Essay', 'Module']\n", "\n", @@ -236,7 +306,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Bonus Challenge - Sort a Dictionary by Values\n", + "# Bonus Challenge - Sort a Dictionary by Values\n", "\n", "Given the dictionary below, sort it by values rather than by keys. Use a lambda function to specify the values as a sorting key." ] @@ -247,6 +317,8 @@ "metadata": {}, "outputs": [], "source": [ + "#BONUS, NO NEEDED TO DO IT\n", + "\n", "d = {'Honda': 1997, 'Toyota': 1995, 'Audi': 2001, 'BMW': 2005}\n", "\n", "# your code here" @@ -269,7 +341,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": true + }, + "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,