From bfea9a4794e957d8d02399b4fc6cd0797b6309ce Mon Sep 17 00:00:00 2001 From: Supratik Koley <41138817+supratikkoley@users.noreply.github.com> Date: Mon, 24 Sep 2018 23:11:13 +0530 Subject: [PATCH 1/4] Created using Colaboratory --- Lists.ipynb | 422 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 422 insertions(+) create mode 100644 Lists.ipynb diff --git a/Lists.ipynb b/Lists.ipynb new file mode 100644 index 0000000..6ef9fea --- /dev/null +++ b/Lists.ipynb @@ -0,0 +1,422 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": " Lists.ipynb", + "version": "0.3.2", + "provenance": [], + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "[View in Colaboratory](https://colab.research.google.com/github/supratikkoley/Assignment-2/blob/supratikkoley/Lists.ipynb)" + ] + }, + { + "metadata": { + "id": "e0R1W0Vzm4UU", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "# Exercise - List" + ] + }, + { + "metadata": { + "id": "TrO7XNQnnQZ7", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "1) Create any random list and assign it to a variable dummy_list" + ] + }, + { + "metadata": { + "id": "bjl-2QkznWid", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "dummy_list=[1,2,3,4,5,6,7,8]" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "cDjddNGfngnp", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "2) print dummy_list" + ] + }, + { + "metadata": { + "id": "RVL5178inz9M", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "9f262d3d-49ca-4aa5-e9ed-cdf843eee89f" + }, + "cell_type": "code", + "source": [ + "print(dummy_list)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[1, 2, 3, 4, 5, 6, 7, 8]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "15jKDXxkn16M", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "3) Reverse dummy_list and print" + ] + }, + { + "metadata": { + "id": "bYa9gFOOn-4o", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "0f9d3ad4-81fc-4b0c-819d-55be04c6b610" + }, + "cell_type": "code", + "source": [ + "dummy_list.reverse()\n", + "print(dummy_list)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[200, 90, 45.67, 16, 12.02, 12.01, 9.45, 8, 7, 6, 5, 4, 4, 3, 2, 2, 1, 1, 0]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "EShv0nfXpUys", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "4) Add the list dummy_list_2 to the previous dummy_list and now print dummy_list" + ] + }, + { + "metadata": { + "id": "Ngkc7hnYphg6", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "30742172-53c4-4873-ebf9-959081369890" + }, + "cell_type": "code", + "source": [ + "dummy_list_2 = [2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n", + "dummy_list += dummy_list_2\n", + "print(dummy_list)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[8, 7, 6, 5, 4, 3, 2, 1, 2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "S3n0ovZAOO0-", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "" + ] + }, + { + "metadata": { + "id": "Le1aRTuYoDzS", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "5) Create a dictionary named dummy_dict which contains all the elements of dummy_list as keys and frequency as values. " + ] + }, + { + "metadata": { + "id": "uLW9R9acOOTt", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "" + ] + }, + { + "metadata": { + "id": "VHfSR_Csthnk", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "dummy_dict={}" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "rtPC6WkSos-y", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "y=[]\n", + "for i in dummy_list:\n", + " if(i not in y):\n", + " y.append(i)\n", + " dummy_dict[i] = 1\n", + " else:\n", + " dummy_dict[i] += 1" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "RgCYpFXGou6q", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "6) print dummy_dict" + ] + }, + { + "metadata": { + "id": "qe5E5IgxpTWU", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "ee8c20d8-c621-4592-b0db-e533997e5c1f" + }, + "cell_type": "code", + "source": [ + "print(dummy_dict)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "{8: 1, 7: 1, 6: 1, 5: 1, 4: 2, 3: 1, 2: 2, 1: 2, 200: 1, 16: 1, 0: 1, 9.45: 1, 45.67: 1, 90: 1, 12.01: 1, 12.02: 1}\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "8n_nsBDup4--", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "7) Sort dummy_list in ascending order as well as descending order and print the changed lists " + ] + }, + { + "metadata": { + "id": "Z_m7vr26qKnK", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "6b2429bd-869d-4a73-901f-d333d52c7c36" + }, + "cell_type": "code", + "source": [ + "dummy_list.sort()\n", + "dummy_list.reverse()\n", + "print(dummy_list)\n" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[90, 45.67, 16, 12.02, 12.01, 9.45, 7, 6, 5, 4, 4, 3, 2, 2, 1, 1]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "Znm5Qo4LqPKA", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "8) Remove the first item from the list whose value is equal to x. It raises a ValueError if there is no such item." + ] + }, + { + "metadata": { + "id": "1-8mlngDqYvS", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 231 + }, + "outputId": "1e944b53-98b1-4421-f359-d5ce108410ee" + }, + "cell_type": "code", + "source": [ + "x = 200\n", + "dummy_list.remove(y.index(x))\n", + "print(dummy_list)\n", + "\n", + "# Let's play: try the same with something which is not in the list to get the ValueError" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "error", + "ename": "ValueError", + "evalue": "ignored", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m200\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mdummy_list\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mremove\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mindex\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdummy_list\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;31m# Let's play: try the same with something which is not in the list to get the ValueError\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mValueError\u001b[0m: list.remove(x): x not in list" + ] + } + ] + }, + { + "metadata": { + "id": "QPB6iGbeqviN", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "9) Remove the item at position x. x is any random integer" + ] + }, + { + "metadata": { + "id": "aMyo1gmRrVHo", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 163 + }, + "outputId": "6e351ae6-6a74-4a2b-fc9b-6b901e54bc6b" + }, + "cell_type": "code", + "source": [ + "# Let's play: try doing the same with x > len(dummy_list) + 1 and see what you get\n", + " dummy_list.remove(len(dummy_list) + 2)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "error", + "ename": "ValueError", + "evalue": "ignored", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdummy_list\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mremove\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdummy_list\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mValueError\u001b[0m: list.remove(x): x not in list" + ] + } + ] + }, + { + "metadata": { + "id": "bqQnnsr8rm6G", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "10) Let's clean everything clear the list and then print" + ] + }, + { + "metadata": { + "id": "qBC8lKpLrtJW", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "a390d9ab-d169-44b9-db0f-d6dcae637151" + }, + "cell_type": "code", + "source": [ + "dummy_list.clear()\n", + "print(dummy_list)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[]\n" + ], + "name": "stdout" + } + ] + } + ] +} \ No newline at end of file From d3559e79c2aec7e5354bfb8f0319f2a3ac4488eb Mon Sep 17 00:00:00 2001 From: Supratik Koley <41138817+supratikkoley@users.noreply.github.com> Date: Wed, 26 Sep 2018 11:00:19 +0530 Subject: [PATCH 2/4] Created using Colaboratory --- supratikkoley.ipynb | 204 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 174 insertions(+), 30 deletions(-) diff --git a/supratikkoley.ipynb b/supratikkoley.ipynb index 9e2543a..fb2d315 100644 --- a/supratikkoley.ipynb +++ b/supratikkoley.ipynb @@ -1,32 +1,176 @@ { - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "supratikkoley.ipynb", + "version": "0.3.2", + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + } }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.5.2" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} + "cells": [ + { + "metadata": { + "id": "ModgWqVeSvgL", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "dummy_list=[1,2,3,4,5,6,7,8]" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "GGP_iKHkRP2R", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "print(dummy_list)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "W1y_w8v1Vxz3", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "dummy_list.reverse()\n", + "print(dummy_list)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "6yqtbDcvV1YF", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "dummy_list_2 = [2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n", + "dummy_list += dummy_list_2\n", + "print(dummy_list)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "wCx9HpC5V47o", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "dummy_dict={}" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "14uaXZfaV-mI", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "y=[]\n", + "for i in dummy_list:\n", + " if(i not in y):\n", + " y.append(i)\n", + " dummy_dict[i] = 1\n", + " else:\n", + " dummy_dict[i] += 1" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "ki9saaVTWEvY", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "print(dummy_dict)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "0BPmAX-wWK_E", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "dummy_list.sort()\n", + "dummy_list.reverse()\n", + "print(dummy_list)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "x62xkjI4WNNv", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "x = 200\n", + "dummy_list.remove(y.index(x))\n", + "print(dummy_list)\n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "LEgcnN6bWX0s", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "# Let's play: try doing the same with x > len(dummy_list) + 1 and see what you get\n", + " dummy_list.remove(len(dummy_list) + 2)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "1qfBxvoaWbCy", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "dummy_list.clear()\n", + "print(dummy_list)" + ], + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file From 6092a79e0b0d6e8c7345672daf657aa9bccf90e9 Mon Sep 17 00:00:00 2001 From: Supratik Koley <41138817+supratikkoley@users.noreply.github.com> Date: Wed, 26 Sep 2018 12:27:07 +0530 Subject: [PATCH 3/4] Created using Colaboratory --- supratikkoley.ipynb | 130 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 109 insertions(+), 21 deletions(-) diff --git a/supratikkoley.ipynb b/supratikkoley.ipynb index fb2d315..ffabc46 100644 --- a/supratikkoley.ipynb +++ b/supratikkoley.ipynb @@ -31,34 +31,62 @@ "metadata": { "id": "GGP_iKHkRP2R", "colab_type": "code", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "98b65b56-0673-45ce-daa9-2818afc08073" }, "cell_type": "code", "source": [ "print(dummy_list)" ], - "execution_count": 0, - "outputs": [] + "execution_count": 2, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[1, 2, 3, 4, 5, 6, 7, 8]\n" + ], + "name": "stdout" + } + ] }, { "metadata": { "id": "W1y_w8v1Vxz3", "colab_type": "code", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "d2612b27-310e-4507-aa19-b1d4acf129fe" }, "cell_type": "code", "source": [ "dummy_list.reverse()\n", "print(dummy_list)" ], - "execution_count": 0, - "outputs": [] + "execution_count": 3, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[8, 7, 6, 5, 4, 3, 2, 1]\n" + ], + "name": "stdout" + } + ] }, { "metadata": { "id": "6yqtbDcvV1YF", "colab_type": "code", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "65ba845a-de05-4423-b76c-a6ef35ebadeb" }, "cell_type": "code", "source": [ @@ -66,8 +94,16 @@ "dummy_list += dummy_list_2\n", "print(dummy_list)" ], - "execution_count": 0, - "outputs": [] + "execution_count": 4, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[8, 7, 6, 5, 4, 3, 2, 1, 2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n" + ], + "name": "stdout" + } + ] }, { "metadata": { @@ -105,20 +141,36 @@ "metadata": { "id": "ki9saaVTWEvY", "colab_type": "code", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "db92658a-58f2-40e5-d0a7-ba79c1d0a146" }, "cell_type": "code", "source": [ "print(dummy_dict)" ], - "execution_count": 0, - "outputs": [] + "execution_count": 7, + "outputs": [ + { + "output_type": "stream", + "text": [ + "{8: 1, 7: 1, 6: 1, 5: 1, 4: 2, 3: 1, 2: 2, 1: 2, 200: 1, 16: 1, 0: 1, 9.45: 1, 45.67: 1, 90: 1, 12.01: 1, 12.02: 1}\n" + ], + "name": "stdout" + } + ] }, { "metadata": { "id": "0BPmAX-wWK_E", "colab_type": "code", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "cbced339-9357-4996-a3ae-e37a35a97e02" }, "cell_type": "code", "source": [ @@ -126,14 +178,26 @@ "dummy_list.reverse()\n", "print(dummy_list)" ], - "execution_count": 0, - "outputs": [] + "execution_count": 8, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[200, 90, 45.67, 16, 12.02, 12.01, 9.45, 8, 7, 6, 5, 4, 4, 3, 2, 2, 1, 1, 0]\n" + ], + "name": "stdout" + } + ] }, { "metadata": { "id": "x62xkjI4WNNv", "colab_type": "code", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "4078abcf-42cd-44e4-9a8d-157425f1ceb5" }, "cell_type": "code", "source": [ @@ -141,22 +205,46 @@ "dummy_list.remove(y.index(x))\n", "print(dummy_list)\n" ], - "execution_count": 0, - "outputs": [] + "execution_count": 9, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[200, 90, 45.67, 16, 12.02, 12.01, 9.45, 7, 6, 5, 4, 4, 3, 2, 2, 1, 1, 0]\n" + ], + "name": "stdout" + } + ] }, { "metadata": { "id": "LEgcnN6bWX0s", "colab_type": "code", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 163 + }, + "outputId": "b5658d35-8362-47ba-e26f-ba5d7b9a6ed9" }, "cell_type": "code", "source": [ "# Let's play: try doing the same with x > len(dummy_list) + 1 and see what you get\n", " dummy_list.remove(len(dummy_list) + 2)" ], - "execution_count": 0, - "outputs": [] + "execution_count": 10, + "outputs": [ + { + "output_type": "error", + "ename": "ValueError", + "evalue": "ignored", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdummy_list\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mremove\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdummy_list\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mValueError\u001b[0m: list.remove(x): x not in list" + ] + } + ] }, { "metadata": { From 61189de35ccd783cf1f0aa9fba8ed91f65b8f178 Mon Sep 17 00:00:00 2001 From: Supratik Koley <41138817+supratikkoley@users.noreply.github.com> Date: Thu, 27 Sep 2018 00:25:25 +0530 Subject: [PATCH 4/4] Created using Colaboratory --- supratikkoley.ipynb | 306 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 287 insertions(+), 19 deletions(-) diff --git a/supratikkoley.ipynb b/supratikkoley.ipynb index ffabc46..3a16812 100644 --- a/supratikkoley.ipynb +++ b/supratikkoley.ipynb @@ -35,13 +35,13 @@ "base_uri": "https://localhost:8080/", "height": 34 }, - "outputId": "98b65b56-0673-45ce-daa9-2818afc08073" + "outputId": "4a339124-5ef2-40cc-f742-a4f8245b74b2" }, "cell_type": "code", "source": [ "print(dummy_list)" ], - "execution_count": 2, + "execution_count": 12, "outputs": [ { "output_type": "stream", @@ -60,14 +60,14 @@ "base_uri": "https://localhost:8080/", "height": 34 }, - "outputId": "d2612b27-310e-4507-aa19-b1d4acf129fe" + "outputId": "9e685192-20ca-45d4-cf27-16c65ac718bb" }, "cell_type": "code", "source": [ "dummy_list.reverse()\n", "print(dummy_list)" ], - "execution_count": 3, + "execution_count": 13, "outputs": [ { "output_type": "stream", @@ -86,7 +86,7 @@ "base_uri": "https://localhost:8080/", "height": 34 }, - "outputId": "65ba845a-de05-4423-b76c-a6ef35ebadeb" + "outputId": "c674ad4a-9c10-4e8d-bea8-e29fca76b7cf" }, "cell_type": "code", "source": [ @@ -94,7 +94,7 @@ "dummy_list += dummy_list_2\n", "print(dummy_list)" ], - "execution_count": 4, + "execution_count": 14, "outputs": [ { "output_type": "stream", @@ -145,13 +145,13 @@ "base_uri": "https://localhost:8080/", "height": 34 }, - "outputId": "db92658a-58f2-40e5-d0a7-ba79c1d0a146" + "outputId": "d414e356-d0c2-40b1-984d-e6550ecdc0a7" }, "cell_type": "code", "source": [ "print(dummy_dict)" ], - "execution_count": 7, + "execution_count": 17, "outputs": [ { "output_type": "stream", @@ -170,7 +170,7 @@ "base_uri": "https://localhost:8080/", "height": 34 }, - "outputId": "cbced339-9357-4996-a3ae-e37a35a97e02" + "outputId": "835f6b4e-a9ae-4cee-b00f-e4593f929ff7" }, "cell_type": "code", "source": [ @@ -178,7 +178,7 @@ "dummy_list.reverse()\n", "print(dummy_list)" ], - "execution_count": 8, + "execution_count": 18, "outputs": [ { "output_type": "stream", @@ -197,7 +197,7 @@ "base_uri": "https://localhost:8080/", "height": 34 }, - "outputId": "4078abcf-42cd-44e4-9a8d-157425f1ceb5" + "outputId": "dac152ff-c48f-4934-dd20-26d0f0709c24" }, "cell_type": "code", "source": [ @@ -205,7 +205,7 @@ "dummy_list.remove(y.index(x))\n", "print(dummy_list)\n" ], - "execution_count": 9, + "execution_count": 19, "outputs": [ { "output_type": "stream", @@ -224,14 +224,14 @@ "base_uri": "https://localhost:8080/", "height": 163 }, - "outputId": "b5658d35-8362-47ba-e26f-ba5d7b9a6ed9" + "outputId": "59afb160-1178-412c-f935-f17b4be0e29a" }, "cell_type": "code", "source": [ "# Let's play: try doing the same with x > len(dummy_list) + 1 and see what you get\n", - " dummy_list.remove(len(dummy_list) + 2)" + " dummy_list.remove(len(dummy_list))" ], - "execution_count": 10, + "execution_count": 20, "outputs": [ { "output_type": "error", @@ -240,7 +240,7 @@ "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdummy_list\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mremove\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdummy_list\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdummy_list\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mremove\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdummy_list\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mValueError\u001b[0m: list.remove(x): x not in list" ] } @@ -250,15 +250,283 @@ "metadata": { "id": "1qfBxvoaWbCy", "colab_type": "code", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "1a9878c7-f25f-475e-b186-2eb507f295c4" }, "cell_type": "code", "source": [ "dummy_list.clear()\n", "print(dummy_list)" ], - "execution_count": 0, - "outputs": [] + "execution_count": 21, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "ORNiJzl2NVBN", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 204 + }, + "outputId": "876b8993-9e96-4e9c-e43f-ddb35216186c" + }, + "cell_type": "code", + "source": [ + "import numpy as np #import numpy\n", + "arr = np.linspace(-1.3,2.5,64)\n", + "print(arr)" + ], + "execution_count": 22, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[-1.3 -1.23968254 -1.17936508 -1.11904762 -1.05873016 -0.9984127\n", + " -0.93809524 -0.87777778 -0.81746032 -0.75714286 -0.6968254 -0.63650794\n", + " -0.57619048 -0.51587302 -0.45555556 -0.3952381 -0.33492063 -0.27460317\n", + " -0.21428571 -0.15396825 -0.09365079 -0.03333333 0.02698413 0.08730159\n", + " 0.14761905 0.20793651 0.26825397 0.32857143 0.38888889 0.44920635\n", + " 0.50952381 0.56984127 0.63015873 0.69047619 0.75079365 0.81111111\n", + " 0.87142857 0.93174603 0.99206349 1.05238095 1.11269841 1.17301587\n", + " 1.23333333 1.29365079 1.35396825 1.41428571 1.47460317 1.53492063\n", + " 1.5952381 1.65555556 1.71587302 1.77619048 1.83650794 1.8968254\n", + " 1.95714286 2.01746032 2.07777778 2.13809524 2.1984127 2.25873016\n", + " 2.31904762 2.37936508 2.43968254 2.5 ]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "VwzrQCVNNo1V", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "2a5d2dc2-3cfc-4cbf-f299-55032a43001d" + }, + "cell_type": "code", + "source": [ + "arr = np.array([1,2,3]*3)\n", + "print(arr)" + ], + "execution_count": 23, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[1 2 3 1 2 3 1 2 3]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "9ac-oWDdNpyd", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "3b3c9094-fcfc-4a0d-d2c7-9d76af4b8a66" + }, + "cell_type": "code", + "source": [ + "odd = np.arange(10)\n", + "odd=odd[odd%2!=0]\n", + "print(odd)" + ], + "execution_count": 24, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[1 3 5 7 9]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "z5A3vG4mNs7y", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "8aac6015-9be1-4092-8049-dfa07e8e934d" + }, + "cell_type": "code", + "source": [ + "#expected output array([2, 4])\n", + "a = np.array([1,2,3,2,3,4,3,4,5,6])\n", + "b = np.array([7,2,10,2,7,4,9,4,9,8])\n", + "c=np.intersect1d(a,b)\n", + "print(c)" + ], + "execution_count": 25, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[2 4]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "XCHRs0rLN3Pi", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 51 + }, + "outputId": "bc47669f-c060-4d93-e0ef-cd5d84dc1430" + }, + "cell_type": "code", + "source": [ + "a = np.arange(10)\n", + "a = a.reshape(2,5)\n", + "print(a)" + ], + "execution_count": 26, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[[0 1 2 3 4]\n", + " [5 6 7 8 9]]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "K4FbDEeyN_HQ", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 51 + }, + "outputId": "aa02b875-38a7-4583-ec10-2d0906ad31af" + }, + "cell_type": "code", + "source": [ + "a = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n", + "arr_a = np.array(a)\n", + "print(arr_a)\n", + "\n", + "list_a = list(arr_a)\n", + "\n", + "print(list_a)" + ], + "execution_count": 27, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[1 2 3 4 5 6 7 8 9]\n", + "[1, 2, 3, 4, 5, 6, 7, 8, 9]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "Oy6t8ICeOCKS", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 187 + }, + "outputId": "3ab5a787-5c2c-43d5-de4e-7aeb92301582" + }, + "cell_type": "code", + "source": [ + "z = np.zeros((10,10))\n", + "# print(z)\n", + "\n", + "z[:,0]=1\n", + "z[:,9]=1\n", + "z[0,:]=1\n", + "z[9,:]=1\n", + "\n", + "print(z)" + ], + "execution_count": 28, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]\n", + " [1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n", + " [1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n", + " [1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n", + " [1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n", + " [1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n", + " [1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n", + " [1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n", + " [1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n", + " [1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "AqJNJDPuOFUi", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 153 + }, + "outputId": "5db3a785-f1f2-40b4-f9b2-1f2ca5fbe6db" + }, + "cell_type": "code", + "source": [ + "x = np.zeros((8,8),dtype=int)\n", + "x[1::2,::2] = 1\n", + "x[::2,1::2] = 1\n", + "print(x)" + ], + "execution_count": 29, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[[0 1 0 1 0 1 0 1]\n", + " [1 0 1 0 1 0 1 0]\n", + " [0 1 0 1 0 1 0 1]\n", + " [1 0 1 0 1 0 1 0]\n", + " [0 1 0 1 0 1 0 1]\n", + " [1 0 1 0 1 0 1 0]\n", + " [0 1 0 1 0 1 0 1]\n", + " [1 0 1 0 1 0 1 0]]\n" + ], + "name": "stdout" + } + ] } ] } \ No newline at end of file