From f26559faeba762e630944514388e495f7f698771 Mon Sep 17 00:00:00 2001 From: "nageswarkv@gmail.com" Date: Sat, 3 May 2025 09:42:56 -0400 Subject: [PATCH 1/3] Assignment 1 changes --- 02_activities/assignments/assignment_1.ipynb | 449 ++++++++++++++++++- 1 file changed, 432 insertions(+), 17 deletions(-) diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index bd82b6b8b..4603cbe9a 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -56,36 +56,337 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 574, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 574, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# For testing purposes, we will write our code in the function\n", - "def anagram_checker(word_a, word_b):\n", - " # Your code here\n", + "# ignoring case sensitivity and spaces\n", + "def anagram_checker(msg1, msg2):\n", + " if(len(msg1)!=len(msg2)):\n", + " return False\n", + " found = True\n", + " for char in msg1.lower():\n", + " if char.isspace():\n", + " continue\n", + " if char not in msg2.lower():\n", + " found = False\n", + " return found\n", + " return found\n", "\n", "# Run your code to check using the words below:\n", "anagram_checker(\"Silent\", \"listen\")" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Another versin of Anagram checker\n" + ] + }, { "cell_type": "code", - "execution_count": null, + "execution_count": 575, "metadata": {}, "outputs": [], + "source": [ + "\n", + "# For testing purposes, we will write our code in the function\n", + "# ignoring case sensitivity and spaces\n", + "def check_anagram(msg1, msg2):\n", + " found = True\n", + " d1 = {}\n", + " d2 = {}\n", + " for char in msg1.lower():\n", + " if char.isspace():\n", + " continue\n", + " if(d1.get(char)):\n", + " d1[char]+=1\n", + " else:\n", + " d1[char]=1\n", + " for char in msg2.lower():\n", + " if char.isspace():\n", + " continue\n", + " if(d2.get(char)):\n", + " d2[char]+=1\n", + " else:\n", + " d2[char]=1\n", + " for key1,val1 in d1.items():\n", + " for key2,val2 in d2.items():\n", + " if(key1==key2 and val1!=val2):\n", + " print('if block',key1,key2,val1,val2)\n", + " found = False\n", + " return found\n", + " \n", + " return found\n" + ] + }, + { + "cell_type": "code", + "execution_count": 576, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 576, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"Silent\", \"Night\")" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Happy path test data" + ] + }, { "cell_type": "code", - "execution_count": null, + "execution_count": 577, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 577, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"night\", \"Thing\")" ] }, + { + "cell_type": "code", + "execution_count": 578, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 578, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"evil\", \"vile\")" + ] + }, + { + "cell_type": "code", + "execution_count": 579, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 579, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"triangle\", \"integral\")" + ] + }, + { + "cell_type": "code", + "execution_count": 580, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 580, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"a gentleman\", \"elegant man\")" + ] + }, + { + "cell_type": "code", + "execution_count": 581, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 581, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"123\", \"321\")" + ] + }, + { + "cell_type": "code", + "execution_count": 582, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 582, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"!@# $%^\", \"^$# @!%\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Not happpy path test data" + ] + }, + { + "cell_type": "code", + "execution_count": 583, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 583, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"hello\", \"billion\")" + ] + }, + { + "cell_type": "code", + "execution_count": 584, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 584, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"test\", \"ttew\")" + ] + }, + { + "cell_type": "code", + "execution_count": 585, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 585, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"abc\", \"abcd\")" + ] + }, + { + "cell_type": "code", + "execution_count": 586, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 586, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"Clint Eastwood\", \"Old West Acton\")" + ] + }, + { + "cell_type": "code", + "execution_count": 587, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 587, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"123\", \"124\")" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -97,24 +398,138 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 588, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 588, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "def anagram_checker(word_a, word_b, is_case_sensitive):\n", - " # Modify your existing code here\n", + "def anagram_checker_with_case(msg1, msg2, is_case_sensitive):\n", + " if(len(msg1)!=len(msg2)):\n", + " return False\n", + " found = True\n", + " if not is_case_sensitive:\n", + " msg1=msg1.lower()\n", + " msg2 = msg2.lower()\n", + " for char in msg1:\n", + " if char.isspace():\n", + " continue\n", + " if char not in msg2:\n", + " found = False\n", + " return found\n", + " return found\n", "\n", "# Run your code to check using the words below:\n", - "anagram_checker(\"Silent\", \"listen\", False) # True" + "anagram_checker_with_case(\"Silent\", \"listen\", False) # True" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 589, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 589, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker_with_case(\"Silent\", \"Listen\", True) # False" + ] + }, + { + "cell_type": "code", + "execution_count": 590, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 590, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker_with_case(\"Triangle\", \"integral\",False)" + ] + }, + { + "cell_type": "code", + "execution_count": 591, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 591, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker_with_case(\"Triangle\", \"integral\",True)" + ] + }, + { + "cell_type": "code", + "execution_count": 592, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 592, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker_with_case(\"Evil\", \"vile\",False)" + ] + }, + { + "cell_type": "code", + "execution_count": 593, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 593, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "anagram_checker(\"Silent\", \"Listen\", True) # False" + "anagram_checker_with_case(\"Evil\", \"vile\",True)" ] }, { @@ -130,7 +545,7 @@ ], "metadata": { "kernelspec": { - "display_name": "new-learner", + "display_name": "dsi_participant", "language": "python", "name": "python3" }, @@ -144,7 +559,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.9.15" } }, "nbformat": 4, From e77a72833b08e17a97d736295ab9c9a56d6e7531 Mon Sep 17 00:00:00 2001 From: "nageswarkv@gmail.com" Date: Sat, 3 May 2025 09:51:59 -0400 Subject: [PATCH 2/3] class notes file deleted --- classwork/class1.ipynb | 59 ------------------------------------------ 1 file changed, 59 deletions(-) delete mode 100644 classwork/class1.ipynb diff --git a/classwork/class1.ipynb b/classwork/class1.ipynb deleted file mode 100644 index 718872378..000000000 --- a/classwork/class1.ipynb +++ /dev/null @@ -1,59 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "5e0be35f", - "metadata": {}, - "source": [ - "# This is Python class notes" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "29be9a11", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Hello World\n" - ] - } - ], - "source": [ - "print(\"Hello World\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "8357b619", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "dsi_participant", - "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.9.15" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} From a9be5561b26343e871e373580b929bb303ea1306 Mon Sep 17 00:00:00 2001 From: "nageswarkv@gmail.com" Date: Tue, 6 May 2025 11:37:18 -0400 Subject: [PATCH 3/3] pr review comments fixed --- 02_activities/assignments/assignment_1.ipynb | 182 ++++++++----------- 1 file changed, 79 insertions(+), 103 deletions(-) diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index 4603cbe9a..97f446424 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -56,7 +56,7 @@ }, { "cell_type": "code", - "execution_count": 574, + "execution_count": 258, "metadata": {}, "outputs": [ { @@ -65,7 +65,7 @@ "True" ] }, - "execution_count": 574, + "execution_count": 258, "metadata": {}, "output_type": "execute_result" } @@ -74,68 +74,24 @@ "# For testing purposes, we will write our code in the function\n", "# ignoring case sensitivity and spaces\n", "def anagram_checker(msg1, msg2):\n", - " if(len(msg1)!=len(msg2)):\n", + " # strip off spaces and convert to lower case\n", + " msg1=msg1.replace(' ','').lower()\n", + " msg2 = msg2.replace(' ','').lower()\n", + " # this is not required but this will prevent right off the bat from running sorted function\n", + " ## if two words are of unequal size\n", + " if len(msg1)!=len(msg2):\n", " return False\n", - " found = True\n", - " for char in msg1.lower():\n", - " if char.isspace():\n", - " continue\n", - " if char not in msg2.lower():\n", - " found = False\n", - " return found\n", - " return found\n", + " msg1 = sorted(msg1)\n", + " msg2 = sorted(msg2)\n", + " return msg1==msg2\n", "\n", "# Run your code to check using the words below:\n", "anagram_checker(\"Silent\", \"listen\")" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Another versin of Anagram checker\n" - ] - }, { "cell_type": "code", - "execution_count": 575, - "metadata": {}, - "outputs": [], - "source": [ - "\n", - "# For testing purposes, we will write our code in the function\n", - "# ignoring case sensitivity and spaces\n", - "def check_anagram(msg1, msg2):\n", - " found = True\n", - " d1 = {}\n", - " d2 = {}\n", - " for char in msg1.lower():\n", - " if char.isspace():\n", - " continue\n", - " if(d1.get(char)):\n", - " d1[char]+=1\n", - " else:\n", - " d1[char]=1\n", - " for char in msg2.lower():\n", - " if char.isspace():\n", - " continue\n", - " if(d2.get(char)):\n", - " d2[char]+=1\n", - " else:\n", - " d2[char]=1\n", - " for key1,val1 in d1.items():\n", - " for key2,val2 in d2.items():\n", - " if(key1==key2 and val1!=val2):\n", - " print('if block',key1,key2,val1,val2)\n", - " found = False\n", - " return found\n", - " \n", - " return found\n" - ] - }, - { - "cell_type": "code", - "execution_count": 576, + "execution_count": 259, "metadata": {}, "outputs": [ { @@ -144,7 +100,7 @@ "False" ] }, - "execution_count": 576, + "execution_count": 259, "metadata": {}, "output_type": "execute_result" } @@ -162,7 +118,7 @@ }, { "cell_type": "code", - "execution_count": 577, + "execution_count": 260, "metadata": {}, "outputs": [ { @@ -171,7 +127,7 @@ "True" ] }, - "execution_count": 577, + "execution_count": 260, "metadata": {}, "output_type": "execute_result" } @@ -182,7 +138,7 @@ }, { "cell_type": "code", - "execution_count": 578, + "execution_count": 261, "metadata": {}, "outputs": [ { @@ -191,7 +147,7 @@ "True" ] }, - "execution_count": 578, + "execution_count": 261, "metadata": {}, "output_type": "execute_result" } @@ -202,7 +158,7 @@ }, { "cell_type": "code", - "execution_count": 579, + "execution_count": 262, "metadata": {}, "outputs": [ { @@ -211,7 +167,7 @@ "True" ] }, - "execution_count": 579, + "execution_count": 262, "metadata": {}, "output_type": "execute_result" } @@ -222,7 +178,7 @@ }, { "cell_type": "code", - "execution_count": 580, + "execution_count": 263, "metadata": {}, "outputs": [ { @@ -231,7 +187,7 @@ "True" ] }, - "execution_count": 580, + "execution_count": 263, "metadata": {}, "output_type": "execute_result" } @@ -242,7 +198,7 @@ }, { "cell_type": "code", - "execution_count": 581, + "execution_count": 264, "metadata": {}, "outputs": [ { @@ -251,7 +207,7 @@ "True" ] }, - "execution_count": 581, + "execution_count": 264, "metadata": {}, "output_type": "execute_result" } @@ -262,7 +218,7 @@ }, { "cell_type": "code", - "execution_count": 582, + "execution_count": 265, "metadata": {}, "outputs": [ { @@ -271,7 +227,7 @@ "True" ] }, - "execution_count": 582, + "execution_count": 265, "metadata": {}, "output_type": "execute_result" } @@ -289,7 +245,7 @@ }, { "cell_type": "code", - "execution_count": 583, + "execution_count": 266, "metadata": {}, "outputs": [ { @@ -298,7 +254,7 @@ "False" ] }, - "execution_count": 583, + "execution_count": 266, "metadata": {}, "output_type": "execute_result" } @@ -309,7 +265,7 @@ }, { "cell_type": "code", - "execution_count": 584, + "execution_count": 267, "metadata": {}, "outputs": [ { @@ -318,7 +274,7 @@ "False" ] }, - "execution_count": 584, + "execution_count": 267, "metadata": {}, "output_type": "execute_result" } @@ -329,7 +285,7 @@ }, { "cell_type": "code", - "execution_count": 585, + "execution_count": 268, "metadata": {}, "outputs": [ { @@ -338,7 +294,7 @@ "False" ] }, - "execution_count": 585, + "execution_count": 268, "metadata": {}, "output_type": "execute_result" } @@ -349,7 +305,7 @@ }, { "cell_type": "code", - "execution_count": 586, + "execution_count": 269, "metadata": {}, "outputs": [ { @@ -358,7 +314,7 @@ "False" ] }, - "execution_count": 586, + "execution_count": 269, "metadata": {}, "output_type": "execute_result" } @@ -369,7 +325,7 @@ }, { "cell_type": "code", - "execution_count": 587, + "execution_count": 270, "metadata": {}, "outputs": [ { @@ -378,7 +334,7 @@ "False" ] }, - "execution_count": 587, + "execution_count": 270, "metadata": {}, "output_type": "execute_result" } @@ -387,6 +343,26 @@ "anagram_checker(\"123\", \"124\")" ] }, + { + "cell_type": "code", + "execution_count": 271, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 271, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"aab\",\"abz\")" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -398,7 +374,7 @@ }, { "cell_type": "code", - "execution_count": 588, + "execution_count": 272, "metadata": {}, "outputs": [ { @@ -407,26 +383,26 @@ "True" ] }, - "execution_count": 588, + "execution_count": 272, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def anagram_checker_with_case(msg1, msg2, is_case_sensitive):\n", - " if(len(msg1)!=len(msg2)):\n", - " return False\n", - " found = True\n", " if not is_case_sensitive:\n", - " msg1=msg1.lower()\n", - " msg2 = msg2.lower()\n", - " for char in msg1:\n", - " if char.isspace():\n", - " continue\n", - " if char not in msg2:\n", - " found = False\n", - " return found\n", - " return found\n", + " msg1=msg1.lower()\n", + " msg2 = msg2.lower()\n", + " #strip off spaces and convert to lower case\n", + " msg1=msg1.replace(' ','')\n", + " msg2 = msg2.replace(' ','')\n", + " #this is not required but this will prevent right off the bat from running sorted function\n", + " ##if two words are of unequal size\n", + " if len(msg1)!=len(msg2):\n", + " return False\n", + " msg1 = sorted(msg1)\n", + " msg2 = sorted(msg2)\n", + " return msg1==msg2\n", "\n", "# Run your code to check using the words below:\n", "anagram_checker_with_case(\"Silent\", \"listen\", False) # True" @@ -434,7 +410,7 @@ }, { "cell_type": "code", - "execution_count": 589, + "execution_count": 273, "metadata": {}, "outputs": [ { @@ -443,7 +419,7 @@ "False" ] }, - "execution_count": 589, + "execution_count": 273, "metadata": {}, "output_type": "execute_result" } @@ -454,7 +430,7 @@ }, { "cell_type": "code", - "execution_count": 590, + "execution_count": 274, "metadata": {}, "outputs": [ { @@ -463,7 +439,7 @@ "True" ] }, - "execution_count": 590, + "execution_count": 274, "metadata": {}, "output_type": "execute_result" } @@ -474,7 +450,7 @@ }, { "cell_type": "code", - "execution_count": 591, + "execution_count": 275, "metadata": {}, "outputs": [ { @@ -483,7 +459,7 @@ "False" ] }, - "execution_count": 591, + "execution_count": 275, "metadata": {}, "output_type": "execute_result" } @@ -494,7 +470,7 @@ }, { "cell_type": "code", - "execution_count": 592, + "execution_count": 276, "metadata": {}, "outputs": [ { @@ -503,7 +479,7 @@ "True" ] }, - "execution_count": 592, + "execution_count": 276, "metadata": {}, "output_type": "execute_result" } @@ -514,7 +490,7 @@ }, { "cell_type": "code", - "execution_count": 593, + "execution_count": 277, "metadata": {}, "outputs": [ { @@ -523,7 +499,7 @@ "False" ] }, - "execution_count": 593, + "execution_count": 277, "metadata": {}, "output_type": "execute_result" }