From 2d845353d8b6881a99024909140cc8b3b424f1eb Mon Sep 17 00:00:00 2001 From: Miguel Marti Date: Tue, 3 May 2022 15:25:03 +0100 Subject: [PATCH] lamb --- your-code/main.ipynb | 140 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 121 insertions(+), 19 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 1ecb24d..b799807 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -34,11 +34,46 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ - "# your code here\n" + "modify_list = [2, 7, 6, 4, 1, 2, 9, 11, 5, 3]\n", + "\n", + "\n", + "\n", + "def my_funct(list, lamfunc):\n", + " empty_list = []\n", + " for element in list:\n", + " x = (lamfunc)(element)\n", + " empty_list.append(x)\n", + " return empty_list\n", + "\n", + "\n", + "\n", + "## (lambda x : x**2)(4)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[4, 9, 8, 6, 3, 4, 11, 13, 7, 5]" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "lamfunc = (lambda x : x + 2)\n", + "\n", + "my_funct(modify_list, lamfunc)" ] }, { @@ -54,9 +89,29 @@ "cell_type": "code", "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Temperature in Kelvin ( K ) = 273.15\n" + ] + } + ], "source": [ - "# Your code here:\n" + "# from degree Celsius to Kelvin\n", + "def Celsius_to_Kelvin(C):\n", + " return (C + 273.15)\n", + " \n", + "# Driver Code\n", + " \n", + "# variable to hold the\n", + "# temperature in Celsius\n", + "C = 0\n", + " \n", + "print(\"Temperature in Kelvin ( K ) = \",\n", + " Celsius_to_Kelvin(C))\n", + "\n" ] }, { @@ -70,11 +125,27 @@ "cell_type": "code", "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[285.15, 296.15, 311.15, 218.14999999999998, 297.15]" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "temps = [12, 23, 38, -55, 24]\n", "\n", - "# Your code here:\n" + "\n", + "\n", + "lamfunc = (lambda temps : temps + 273.15)\n", + "\n", + "my_funct(temps, lamfunc)\n", + "\n" ] }, { @@ -88,7 +159,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -106,7 +177,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -127,7 +198,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -174,7 +245,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -209,17 +280,32 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "list1 = [1,2,4,4]\n", "list2 = [2,3,3,5]\n", - "## Zip the lists together \n", + "\n", + "zipped = zip(list1,list2)\n", + "list(zipped)\n", "\n", "## Print the zipped list \n", "\n", - "## Use a lambda expression to compare if: list1 element > list2 element\n" + "## Use a lambda expression to compare if: list1 element > list2 element\n", + "## list1 (element) > list2 (element)\n", + "list1 > list2" ] }, { @@ -242,14 +328,30 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[('Engineering', 'Lab'),\n", + " ('Computer Science', 'Homework'),\n", + " ('Political Science', 'Essay'),\n", + " ('Mathematics', 'Module')]" + ] + }, + "execution_count": 18, + "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", + "zipped = zip(list1,list2)\n", + "list(zipped)" ] }, { @@ -263,7 +365,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -296,7 +398,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.7.9" } }, "nbformat": 4,