diff --git a/02_activities/assignments/DSI_Python.ipynb b/02_activities/assignments/DSI_Python.ipynb new file mode 100644 index 000000000..ce34c8ccd --- /dev/null +++ b/02_activities/assignments/DSI_Python.ipynb @@ -0,0 +1,123 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "code", + "source": [ + " #PART 1\n", + "\n", + "\n", + "from collections import Counter\n", + "\n", + "def anagram_checker(word_a, word_b, is_case_sensitive=False):\n", + " \"\"\"\n", + " Checks if two words are anagrams of each other.\n", + "\n", + " Parameters:\n", + " word_a (str): The first word.\n", + " word_b (str): The second word.\n", + " is_case_sensitive (bool): If True, considers case sensitivity in anagram checking.\n", + "\n", + " Returns:\n", + " bool: True if words are anagrams, False otherwise.\n", + " \"\"\"\n", + " # Normalize words: Remove spaces and apply lowercase if case sensitivity is off\n", + " if not is_case_sensitive:\n", + " word_a = word_a.lower()\n", + " word_b = word_b.lower()\n", + "\n", + " # Use Counter to compare character occurrences\n", + " return Counter(word_a) == Counter(word_b)\n", + "\n", + "# Test Cases\n", + "print(anagram_checker(\"Silent\", \"listen\", False)) # Expected: True\n", + "print(anagram_checker(\"Silent\", \"Listen\", True)) # Expected: False\n", + "print(anagram_checker(\"Silent\", \"Night\", False)) # Expected: False\n", + "print(anagram_checker(\"night\", \"Thing\", False)) # Expected: True\n" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "f3oB2Z02wpwS", + "outputId": "eac66ff9-89ae-4bdb-bb6d-9344245c7049" + }, + "execution_count": 2, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "True\n", + "False\n", + "False\n", + "True\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "def anagram_checker(word_a, word_b, is_case_sensitive=False):\n", + " \"\"\"\n", + " Checks if two words are anagrams of each other with an optional case-sensitive check.\n", + "\n", + " Parameters:\n", + " word_a (str): The first word.\n", + " word_b (str): The second word.\n", + " is_case_sensitive (bool): If True, considers case sensitivity in anagram checking.\n", + "\n", + " Returns:\n", + " bool: True if words are anagrams, False otherwise.\n", + " \"\"\"\n", + " # Normalize words: Remove spaces, apply lowercase if case sensitivity is off\n", + " if not is_case_sensitive:\n", + " word_a = word_a.lower()\n", + " word_b = word_b.lower()\n", + "\n", + " # Use Counter to compare character occurrences\n", + " return Counter(word_a) == Counter(word_b)\n", + "\n", + "# Test Cases for Part 2\n", + "print(anagram_checker(\"Silent\", \"listen\", False)) # Expected: True\n", + "print(anagram_checker(\"Silent\", \"Listen\", True)) # Expected: False\n", + "print(anagram_checker(\"Silent\", \"Night\", False)) # Expected: False\n", + "print(anagram_checker(\"night\", \"Thing\", False)) # Expected: True\n" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "pJdptaCPw0nK", + "outputId": "209fdf88-4ca4-414c-fca6-cef759d55746" + }, + "execution_count": 3, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "True\n", + "False\n", + "False\n", + "True\n" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/Assignment-1.ipynb b/Assignment-1.ipynb new file mode 100644 index 000000000..bed3d9643 --- /dev/null +++ b/Assignment-1.ipynb @@ -0,0 +1,135 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "authorship_tag": "ABX9TyMWnXObtyzsz92ucZBuFrDu", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "code", + "source": [ + " #PART 1\n", + "\n", + "\n", + "from collections import Counter\n", + "\n", + "def anagram_checker(word_a, word_b, is_case_sensitive=False):\n", + " \"\"\"\n", + " Checks if two words are anagrams of each other.\n", + "\n", + " Parameters:\n", + " word_a (str): The first word.\n", + " word_b (str): The second word.\n", + " is_case_sensitive (bool): If True, considers case sensitivity in anagram checking.\n", + "\n", + " Returns:\n", + " bool: True if words are anagrams, False otherwise.\n", + " \"\"\"\n", + " # Normalize words: Remove spaces and apply lowercase if case sensitivity is off\n", + " if not is_case_sensitive:\n", + " word_a = word_a.lower()\n", + " word_b = word_b.lower()\n", + "\n", + " # Use Counter to compare character occurrences\n", + " return Counter(word_a) == Counter(word_b)\n", + "\n", + "# Test Cases\n", + "print(anagram_checker(\"Silent\", \"listen\", False)) # Expected: True\n", + "print(anagram_checker(\"Silent\", \"Listen\", True)) # Expected: False\n", + "print(anagram_checker(\"Silent\", \"Night\", False)) # Expected: False\n", + "print(anagram_checker(\"night\", \"Thing\", False)) # Expected: True\n" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "f3oB2Z02wpwS", + "outputId": "eac66ff9-89ae-4bdb-bb6d-9344245c7049" + }, + "execution_count": 2, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "True\n", + "False\n", + "False\n", + "True\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "def anagram_checker(word_a, word_b, is_case_sensitive=False):\n", + " \"\"\"\n", + " Checks if two words are anagrams of each other with an optional case-sensitive check.\n", + "\n", + " Parameters:\n", + " word_a (str): The first word.\n", + " word_b (str): The second word.\n", + " is_case_sensitive (bool): If True, considers case sensitivity in anagram checking.\n", + "\n", + " Returns:\n", + " bool: True if words are anagrams, False otherwise.\n", + " \"\"\"\n", + " # Normalize words: Remove spaces, apply lowercase if case sensitivity is off\n", + " if not is_case_sensitive:\n", + " word_a = word_a.lower()\n", + " word_b = word_b.lower()\n", + "\n", + " # Use Counter to compare character occurrences\n", + " return Counter(word_a) == Counter(word_b)\n", + "\n", + "# Test Cases for Part 2\n", + "print(anagram_checker(\"Silent\", \"listen\", False)) # Expected: True\n", + "print(anagram_checker(\"Silent\", \"Listen\", True)) # Expected: False\n", + "print(anagram_checker(\"Silent\", \"Night\", False)) # Expected: False\n", + "print(anagram_checker(\"night\", \"Thing\", False)) # Expected: True\n" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "pJdptaCPw0nK", + "outputId": "209fdf88-4ca4-414c-fca6-cef759d55746" + }, + "execution_count": 3, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "True\n", + "False\n", + "False\n", + "True\n" + ] + } + ] + } + ] +} \ No newline at end of file