From 0d34c3db34fe446389788f168bab31d2692b01f6 Mon Sep 17 00:00:00 2001 From: ernestom1412 <88721535+ernestom1412@users.noreply.github.com> Date: Sat, 28 Aug 2021 22:33:13 -0400 Subject: [PATCH] Add files via upload --- your-code/main.ipynb | 192 ++++++++++++++++++++++++++++++------------- 1 file changed, 134 insertions(+), 58 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 66a9984..6bb7dce 100755 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -34,18 +34,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]\n" + ] + } + ], "source": [ - "l = [######]\n", - "f = lambda x: #define the lambda expression\n", + "l = [1,2,3,4,5,6,7,8,9,10]\n", + "f = lambda x: x*2#define the lambda expression\n", "b = []\n", "def modify_list(lst, fudduLambda):\n", - " for x in ####:\n", - " b.append(#####(x))\n", + " for x in lst:####:\n", + " b.append(fudduLambda(x))#####(x))\n", "#Call modify_list(##,##)\n", - "#print b" + "#print b\n", + "modify_list(l,f)\n", + "print(b)" ] }, { @@ -59,12 +69,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" ] }, { @@ -76,13 +86,26 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[285.15, 296.15, 311.15, 218.15, 297.15]\n" + ] + } + ], "source": [ "temps = [12, 23, 38, -55, 24]\n", - "\n", - "# Your code here:" + "# Your code here:\n", + "tempsK=[]\n", + "def C_to_K_f(lst,lam):\n", + " for temp in lst:\n", + " tempsK.append(round(lam(temp),2))\n", + "C_to_K_f(temps,C_to_K)\n", + "print(tempsK)" ] }, { @@ -96,11 +119,12 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ - "# Your code here:\n" + "# Your code here:\n", + "mod=lambda x,y: 1 if x%y==0 else 0" ] }, { @@ -114,7 +138,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -123,8 +147,8 @@ " 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", - " # Your code here:" + " # Your code here:\n", + " return lambda x:mod(x,b)" ] }, { @@ -136,11 +160,12 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ - "# Your code here:\n" + "# Your code here:\n", + "divisible5=divisor(5)" ] }, { @@ -152,18 +177,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "divisible5(10)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "divisible5(8)" ] @@ -183,7 +230,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -195,7 +242,7 @@ " ('tomato', 'tomato')]" ] }, - "execution_count": 1, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -218,14 +265,26 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[(1, 2), (2, 3), (3, 4), (4, 5)]" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "list1 = [1,2,3,4]\n", "list2 = [2,3,4,5]\n", "## Zip the lists together \n", - "## Print the zipped list " + "## Print the zipped list \n", + "list(zip(list1,list2))" ] }, { @@ -237,28 +296,24 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 11, "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": [ - "'''\n", - "\n", - "compare = lambda ###: print(\"True\") if ### else print(\"False\")\n", - "for ### in zip(list1,list2):\n", - " compare(###)\n", - " \n", - "''' " + "compare = lambda x,y: print(\"True\") if x>y else print(\"False\")\n", + "for x,y in zip(list1,list2):\n", + " compare(x,y)" ] }, { @@ -274,14 +329,29 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[('Political Science', 'Essay'),\n", + " ('Computer Science', 'Homework'),\n", + " ('Engineering', 'Lab'),\n", + " ('Mathematics', 'Module')]" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "list1 = ['Engineering', 'Computer Science', 'Political Science', 'Mathematics']\n", "list2 = ['Lab', 'Homework', 'Essay', 'Module']\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "sorted(zip(list1,list2), key=lambda x: x[1])" ] }, { @@ -297,19 +367,25 @@ "cell_type": "code", "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[('Toyota', 1995), ('Honda', 1997), ('Audi', 2001), ('BMW', 2005)]" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "d = {'Honda': 1997, 'Toyota': 1995, 'Audi': 2001, 'BMW': 2005}\n", "\n", - "# Your code here:" + "# Your code here:\n", + "dictvalues = lambda x: x[1]\n", + "sorted(d.items(), key=dictvalues)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -328,7 +404,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.8.8" } }, "nbformat": 4,