diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 1ecb24d..fcffe64 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -34,13 +34,40 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[3, 4, 5, 6, 7, 8, 9, 10, 11, 12]\n" + ] + } + ], "source": [ - "# your code here\n" + "# your code here\n", + "\n", + "list = [1,2,3,4,5,6,7,8,9,10]\n", + "simple_lambda = lambda x : x + 2\n", + "list4 =[]\n", + "\n", + "def new_list (list, fun):\n", + " for x in list:\n", + " list4.append(fun(x))\n", + "\n", + "new_list(list,simple_lambda)\n", + "\n", + "print(list4)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "metadata": {}, @@ -52,13 +79,22 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ - "# Your code here:\n" + "# Your code here:\n", + "\n", + "celsius_to_kelvin = lambda x :x + 273,15" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "metadata": {}, @@ -68,13 +104,27 @@ }, { "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:\n" + "# Your code here:\n", + "\n", + "celsius_to_kelvin = lambda x: x + 273.15\n", + "temps = [12, 23, 38, -55, 24]\n", + "\n", + "new_list = [celsius_to_kelvin(x) for x in temps]\n", + "print(new_list)" ] }, { @@ -88,13 +138,36 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# Your code here:\n" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "mod = lambda x,y: 1 if x%y == 0 or y%x ==0 else 0" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "metadata": {}, @@ -115,9 +188,18 @@ " 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", - " # Your code here:\n" + " # Your code here:\n", + " \n", + " return_mod = lambda x : 1 if x % a == 0 else 0 \n" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "metadata": {}, @@ -131,7 +213,8 @@ "metadata": {}, "outputs": [], "source": [ - "# Your code here:\n" + "# Your code here:\n", + "\n" ] }, { @@ -174,21 +257,19 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 7, "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "[('Green', 'eggs'),\n", - " ('cheese', 'cheese'),\n", - " ('English', 'cucumber'),\n", - " ('tomato', 'tomato')]" - ] - }, - "execution_count": 1, - "metadata": {}, - "output_type": "execute_result" + "ename": "TypeError", + "evalue": "'list' object is not callable", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[7], line 4\u001b[0m\n\u001b[1;32m 2\u001b[0m list2 \u001b[38;5;241m=\u001b[39m [\u001b[38;5;124m'\u001b[39m\u001b[38;5;124meggs\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mcheese\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mcucumber\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtomato\u001b[39m\u001b[38;5;124m'\u001b[39m]\n\u001b[1;32m 3\u001b[0m zipped \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mzip\u001b[39m(list1,list2)\n\u001b[0;32m----> 4\u001b[0m \u001b[38;5;28;43mlist\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mzipped\u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[0;31mTypeError\u001b[0m: 'list' object is not callable" + ] } ], "source": [ @@ -217,11 +298,57 @@ "list2 = [2,3,3,5]\n", "## Zip the lists together \n", "\n", + "\n", "## Print the zipped list \n", "\n", + "\n", "## Use a lambda expression to compare if: list1 element > list2 element\n" ] }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[False, False, True, False]" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\n", + "Lists = [x > y for x, y in zip(list1, list2)]\n", + "\n", + "Lists" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "metadata": {}, @@ -242,16 +369,49 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 14, "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:\n" + "# Your code here:\n", + "zipped = zip(list1, list2)\n", + "\n", + "sort = sorted(zipped, key=lambda x: x[1][0])\n", + "print(sort)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "metadata": {}, @@ -282,7 +442,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -296,7 +456,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.10.9" } }, "nbformat": 4,