From 2995afb21c73bf586410e19193cb51a55234f122 Mon Sep 17 00:00:00 2001 From: yidic <71389648+yidic@users.noreply.github.com> Date: Sun, 25 Oct 2020 21:17:36 +0100 Subject: [PATCH] Yidi --- your-code/main.ipynb | 149 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 129 insertions(+), 20 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 01257d4..f124e1a 100755 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -23,15 +23,40 @@ "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[10, 11, 12]\n" + ] + } + ], "source": [ "def modify_list(lst, lmbda):\n", " \"\"\"\n", " Input: list and lambda expression\n", " Output: the transformed list\n", " \"\"\"\n", - " \n", + "\n", " # your code here\n", + " new_list=[]\n", + " for i in lst:\n", + " new_list.append(lmbda(i))\n", + " print(new_list)\n", + " \n", + " \n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "list1=[5,6,7]\n", + "\n", + "modify_list(list1, lambda x: x+5)\n", + "\n", + "\n", " " ] }, @@ -46,11 +71,22 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "# your code here\n", + "\n", + "def func(lst,lmbda):\n", + " kelvin=[]\n", + " for i in lst:\n", + " kelvin.append(lmbda(i))\n", + " print(kelvin)\n", + "\n", + "\n", + "f = lambda x: x + 273.15\n", + "\n", + "\n" ] }, { @@ -62,13 +98,25 @@ }, { "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.14999999999998, 297.15]\n" + ] + } + ], "source": [ "temps = [12, 23, 38, -55, 24]\n", "\n", - "# your code here" + "# your code here\n", + "\n", + "\n", + "func (temps, lambda x: x + 273.15)\n", + " " ] }, { @@ -82,11 +130,14 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "# your code here\n", + "\n", + "\n", + "mod = (lambda x,y : 1 if x % y == 1 or x % y ==0 else 0 )" ] }, { @@ -100,7 +151,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -111,7 +162,10 @@ " divisible by another number (to be passed later) and zero otherwise.\n", " \"\"\"\n", " \n", - " # your code here" + " # your code here\n", + " \n", + " \n", + " " ] }, { @@ -123,7 +177,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -199,14 +253,54 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[('Green', 'eggs'),\n", + " ('cheese', 'cheese'),\n", + " ('English', 'cucumber'),\n", + " ('tomato', 'tomato')]" + ] + }, + "execution_count": 17, + "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)]\n", + "list3 = zip(list1,list2)\n", + "list(list3)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[('Green', 'eggs'),\n", + " ('cheese', 'cheese'),\n", + " ('English', 'cucumber'),\n", + " ('tomato', 'tomato')]" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "[x for x in zip(list1,list2)]" ] }, { @@ -222,14 +316,29 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[('Lab', 'Engineering'),\n", + " ('Homework', 'Computer Science'),\n", + " ('Essay', 'Political Science'),\n", + " ('Module', 'Mathematics')]" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "list1 = ['Engineering', 'Computer Science', 'Political Science', 'Mathematics']\n", "list2 = ['Lab', 'Homework', 'Essay', 'Module']\n", "\n", - "# your code here" + "# your code here\n", + "[x for x in zip(list2,list1)]\n" ] }, { @@ -243,7 +352,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -269,7 +378,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.7.6" } }, "nbformat": 4,