From 456b1d408a194fdf64522acf73a238e39600ce8f Mon Sep 17 00:00:00 2001 From: Mariangel Date: Sun, 29 Aug 2021 23:58:58 -0400 Subject: [PATCH] my work --- your-code/main.ipynb | 212 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 171 insertions(+), 41 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 66a9984..2501687 100755 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -34,18 +34,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 9, 36, 49, 64, 81, 81, 121, 1156, 100]\n" + ] + } + ], "source": [ - "l = [######]\n", - "f = lambda x: #define the lambda expression\n", + "l = [1, 3, 6, 7, 8, 9, 9, 11, 34, 10]\n", + "f = lambda x: x**2\n", "b = []\n", "def modify_list(lst, fudduLambda):\n", - " for x in ####:\n", - " b.append(#####(x))\n", - "#Call modify_list(##,##)\n", - "#print b" + " for x in l:\n", + " b.append(f(x))\n", + "modify_list(l,f)\n", + "print(b)" ] }, { @@ -59,12 +67,12 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# Your code here:\n", - "\n" + "C_to_k = lambda x: x + 273.15\n" ] }, { @@ -76,13 +84,60 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "temps = [12, 23, 38, -55, 24]\n", "\n", - "# Your code here:" + "\n", + "temps2 = []\n", + "for i in temps:\n", + " temps2.append(C_to_k(i))\n", + " \n", + "\n", + "#convert" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[285.15, 296.15, 311.15, 218.14999999999998, 297.15]" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "temps2" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[285.15, 296.15, 311.15, 218.14999999999998, 297.15]" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "coverter = list(map(C_to_k, temps))\n", + "coverter" ] }, { @@ -96,11 +151,12 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ - "# Your code here:\n" + "# Your code here:\n", + "mod = lambda x, y: 1 if x % y == 0 else 0" ] }, { @@ -114,7 +170,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 72, "metadata": {}, "outputs": [], "source": [ @@ -123,7 +179,7 @@ " input: a number\n", " output: a function that returns 1 if the number is divisible by another number (to be passed later) and zero otherwise\n", " \"\"\"\n", - " \n", + " return lambda x:mod(x, b)\n", " # Your code here:" ] }, @@ -136,11 +192,12 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 73, "metadata": {}, "outputs": [], "source": [ - "# Your code here:\n" + "# Your code here:\n", + "divisible5 = divisor(5)" ] }, { @@ -152,18 +209,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 74, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 74, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "divisible5(10)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 75, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 75, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "divisible5(8)" ] @@ -183,7 +262,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -195,7 +274,7 @@ " ('tomato', 'tomato')]" ] }, - "execution_count": 1, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -218,14 +297,23 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[(1, 2), (2, 3), (3, 4), (4, 5)]\n" + ] + } + ], "source": [ "list1 = [1,2,3,4]\n", "list2 = [2,3,4,5]\n", - "## Zip the lists together \n", - "## Print the zipped list " + "## Zip the lists together\n", + "zipped = zip(list1, list2)\n", + "print(list(zipped))" ] }, { @@ -237,18 +325,18 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 35, "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "'\\n\\ncompare = lambda ###: print(\"True\") if ### else print(\"False\")\\nfor ### in zip(list1,list2):\\n compare(###)\\n \\n'" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "False\n", + "False\n", + "False\n" + ] } ], "source": [ @@ -258,7 +346,10 @@ "for ### in zip(list1,list2):\n", " compare(###)\n", " \n", - "''' " + "''' \n", + "compare = lambda x, j: print('True') if x > j else print('False')\n", + "for i, j in zip(list1, list2):\n", + " compare(i, j)" ] }, { @@ -274,16 +365,55 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 60, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[('Political Science', 'Essay'),\n", + " ('Computer Science', 'Homework'),\n", + " ('Engineering', 'Lab'),\n", + " ('Mathematics', 'Module')]" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "list1 = ['Engineering', 'Computer Science', 'Political Science', 'Mathematics']\n", "list2 = ['Lab', 'Homework', 'Essay', 'Module']\n", "\n", + "zipped = zip(list1, list2)\n", + "new = (list(zipped))\n", + "#print(new)\n", + "\n", + "sorted(new, key=lambda x:x[1])\n", "# Your code here:\n" ] }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'L'" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "new.sort(key = [0][1][0]" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -328,7 +458,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.8.8" } }, "nbformat": 4,