diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 01257d4..9d545b2 100755 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -30,8 +30,7 @@ " Input: list and lambda expression\n", " Output: the transformed list\n", " \"\"\"\n", - " \n", - " # your code here\n", + " return [lmbda(elem) for elem in lst]\n", " " ] }, @@ -46,11 +45,11 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "lmbda_func = lambda x: x + 273.15" ] }, { @@ -62,13 +61,24 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[285.15, 296.15, 311.15, 218.14999999999998, 297.15]" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "temps = [12, 23, 38, -55, 24]\n", "\n", - "# your code here" + "modify_list(temps,lmbda_func)" ] }, { @@ -82,11 +92,11 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "mod = lambda x,y : 1 if x%y == 0 else 0" ] }, { @@ -100,7 +110,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -110,8 +120,7 @@ " Output: a function that returns 1 if the number is \n", " divisible by another number (to be passed later) and zero otherwise.\n", " \"\"\"\n", - " \n", - " # your code here" + " return lambda y : 1 if y%b == 0 else 0" ] }, { @@ -123,11 +132,11 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "divisible5 = divisor(5)" ] }, { @@ -139,18 +148,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)" ] @@ -168,7 +199,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -177,7 +208,7 @@ "[(1,), (2,), (3,), (4,), (5,)]" ] }, - "execution_count": 10, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -199,14 +230,28 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[('Green', 'eggs'),\n", + " ('cheese', 'cheese'),\n", + " ('English', 'cucumber'),\n", + " ('tomato', 'tomato')]" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "list1 = ['Green', 'cheese', 'English', 'tomato']\n", "list2 = ['eggs', 'cheese', 'cucumber', 'tomato']\n", "\n", - "# your code here" + "[x for x in zip(list1,list2)]" ] }, { @@ -222,14 +267,24 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[('Political Science', 'Essay'), ('Computer Science', 'Homework'), ('Engineering', 'Lab'), ('Mathematics', 'Module')]\n" + ] + } + ], "source": [ "list1 = ['Engineering', 'Computer Science', 'Political Science', 'Mathematics']\n", "list2 = ['Lab', 'Homework', 'Essay', 'Module']\n", "\n", - "# your code here" + "zipped_list = list(zip(list1,list2))\n", + "zipped_list.sort(key = lambda pair: pair[1][0])\n", + "print(zipped_list)" ] }, { @@ -243,13 +298,22 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 19, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[('Toyota', 1995), ('Honda', 1997), ('Audi', 2001), ('BMW', 2005)]\n" + ] + } + ], "source": [ "d = {'Honda': 1997, 'Toyota': 1995, 'Audi': 2001, 'BMW': 2005}\n", - "\n", - "# your code here" + "dict_list = list(d.items())\n", + "dict_list.sort(key = lambda pair: pair[1])\n", + "print(dict_list)" ] } ], @@ -269,7 +333,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.8.3" } }, "nbformat": 4,