From 38089a51f348eee0c601e28a3e690eb41401cc24 Mon Sep 17 00:00:00 2001 From: syedabdullahbukhari77 Date: Thu, 21 Aug 2025 19:08:25 +0500 Subject: [PATCH] [--update: Modified Excercises/Python Session Fundamentals/Python Session 02] --- .../Python_Session_02.ipynb | 223 +++++++++++++++++- 1 file changed, 222 insertions(+), 1 deletion(-) diff --git a/Logic Building Exercises/Python Sessions Fundamentals/Python Session - 02/Python_Session_02.ipynb b/Logic Building Exercises/Python Sessions Fundamentals/Python Session - 02/Python_Session_02.ipynb index cc03146..b2ad098 100644 --- a/Logic Building Exercises/Python Sessions Fundamentals/Python Session - 02/Python_Session_02.ipynb +++ b/Logic Building Exercises/Python Sessions Fundamentals/Python Session - 02/Python_Session_02.ipynb @@ -324,11 +324,232 @@ } ] }, + { + "cell_type": "code", + "source": [ + "repeating_list: list = []\n", + "\n", + "def repeat_n(numbers: list) -> None:\n", + " for n in numbers:\n", + " if (n == n+1):\n", + " repeating_list.append(n)\n", + " else: print('no repeatation')\n", + "\n", + "repeat_n([1, 2 , 3 ,4 ,5 , 4 ,2])" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "rEXmyQ4otUzj", + "outputId": "fdb4996d-d5a1-4216-d6a5-c02614a6579e" + }, + "execution_count": 2, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "no repeatation\n", + "no repeatation\n", + "no repeatation\n", + "no repeatation\n", + "no repeatation\n", + "no repeatation\n", + "no repeatation\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "rep_list: list = []\n", + "\n", + "def fn_list(numbers: list):\n", + " for n in numbers:\n", + " if (n + 1 == n) & (n == n+1):\n", + " rep_list.append(n)\n", + " print('repeating!')\n", + " else: print('No repeating')\n", + "\n", + "\n", + "print(rep_list)\n", + "\n", + "fn_list([1 , 2 , 3 , 4 , 5 , 2 ,3])\n", + "fn_list([6 , 7 , 1 , 4 , 7])" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "fftokFA2a93W", + "outputId": "d9303613-5903-4f64-fbc0-3a3193ecfa8c" + }, + "execution_count": 14, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[]\n", + "No repeating\n", + "No repeating\n", + "No repeating\n", + "No repeating\n", + "No repeating\n", + "No repeating\n", + "No repeating\n", + "No repeating\n", + "No repeating\n", + "No repeating\n", + "No repeating\n", + "No repeating\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "def find_first_repeat(numbers: list):\n", + " seen_ = set()\n", + " for n in numbers:\n", + " if (n in seen_):\n", + " return n\n", + " seen_.add(n)\n", + " return 'No repeating'" + ], + "metadata": { + "id": "r9EbVHzPbePF" + }, + "execution_count": 15, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "print(find_first_repeat([1, 2, 3, 4, 5, 2, 3]))" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "1EfJ3m50x9hL", + "outputId": "b96052fb-5fc0-4822-bb88-d63b5295a392" + }, + "execution_count": 16, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "2\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "def find_first_repeat(numbers: list) -> None:\n", + " try:\n", + " seen = set()\n", + "\n", + " for n in numbers:\n", + " if n in seen:\n", + " return n\n", + " seen.append(n)\n", + " return 'No repeat!'\n", + "\n", + " except TypeError:\n", + " return 'Invalid input: Please pass a list of numbers'\n", + "" + ], + "metadata": { + "id": "g8iyZuulyhY1" + }, + "execution_count": 17, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "def most_frequent(numbers: list) -> int:\n", + " dic_count: dict = {}\n", + " for n in numbers:\n", + " if n in dic_count:\n", + " dic_count[n] += 1\n", + " else:\n", + " dic_count[n] = 1\n", + "\n", + " most_frequent()" + ], + "metadata": { + "id": "i3Ml9aKy5pAK" + }, + "execution_count": 18, + "outputs": [] + }, + { + "cell_type": "code", + "source": [], + "metadata": { + "id": "7dbIWCM67kQi" + }, + "execution_count": 32, + "outputs": [] + }, + { + "cell_type": "code", + "source": [], + "metadata": { + "id": "vEcUfxT075jW" + }, + "execution_count": 32, + "outputs": [] + }, + { + "cell_type": "code", + "source": [], + "metadata": { + "id": "UmOTNRQD75lW" + }, + "execution_count": 32, + "outputs": [] + }, + { + "cell_type": "code", + "source": [], + "metadata": { + "id": "wSd5e2d_75nZ" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [], + "metadata": { + "id": "D-ZPAwKi7kS0" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [], + "metadata": { + "id": "q59IHbbo7BEa" + }, + "execution_count": 18, + "outputs": [] + }, { "cell_type": "code", "source": [], "metadata": { - "id": "rEXmyQ4otUzj" + "id": "qPnQ_N5E7BGc" }, "execution_count": null, "outputs": []