From a50fb8c22e264169a61f5626f8f1fe51dd5825c3 Mon Sep 17 00:00:00 2001 From: Ceci Date: Sun, 19 Oct 2025 13:33:00 -0400 Subject: [PATCH 1/4] Completed Part 1 --- 02_activities/assignments/assignment_1.ipynb | 72 +++++++++++++++++--- 1 file changed, 64 insertions(+), 8 deletions(-) diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index bee48d5a0..c9726ff6a 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -58,11 +58,43 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ + "\n", "# For testing purposes, we will write our code in the function\n", "def anagram_checker(word_a, word_b):\n", - " # Your code here\n", + " \n", + " ''' Given two valid strings, check if they are anagrams.\n", + " anagram_checker is a boolean comparator: \n", + " True if the two strings are anagrams; False if the two strings are not anagrams.\n", + " Print message to inddicate whether the two strings are anagrams. '''\n", + " \n", + " # Perform an ascending sort of the characters contained in both string arguments\n", + " word1 = 'word_a'\n", + " sorted_word1 = sorted(word1)\n", + " word2 = 'word_b'\n", + " sorted_word2 = sorted(word2)\n", + "\n", + " # Print the two sorted string lists \n", + " print('String one: ', sorted_word1)\n", + " print('String two: ', sorted_word2)\n", + "\n", + " # Perform a boolean comparison and print the result\n", + " if word1 == word2:\n", + " print('The two strings are anagrams of each other')\n", + " else:\n", + " print('The two strings are not anagrams.')\n", "\n", "# Run your code to check using the words below:\n", "anagram_checker(\"Silent\", \"listen\")" @@ -70,18 +102,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 46, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"Silent\", \"Night\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 47, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"night\", \"Thing\")" ] @@ -104,6 +158,8 @@ "def anagram_checker(word_a, word_b, is_case_sensitive):\n", " # Modify your existing code here\n", "\n", + " \n", + "\n", "# Run your code to check using the words below:\n", "anagram_checker(\"Silent\", \"listen\", False) # True" ] @@ -130,7 +186,7 @@ ], "metadata": { "kernelspec": { - "display_name": "new-learner", + "display_name": "python-env", "language": "python", "name": "python3" }, @@ -144,7 +200,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.11.13" } }, "nbformat": 4, From c7222872468273d247bce68ad7d3fafa80bafbb7 Mon Sep 17 00:00:00 2001 From: Ceci Date: Sun, 19 Oct 2025 16:54:47 -0400 Subject: [PATCH 2/4] Completed Part 2 --- 02_activities/assignments/assignment_1.ipynb | 91 ++++++++++++++------ 1 file changed, 66 insertions(+), 25 deletions(-) diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index c9726ff6a..8b118044f 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -56,7 +56,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 44, "metadata": {}, "outputs": [ { @@ -65,7 +65,7 @@ "True" ] }, - "execution_count": 45, + "execution_count": 44, "metadata": {}, "output_type": "execute_result" } @@ -78,23 +78,20 @@ " ''' Given two valid strings, check if they are anagrams.\n", " anagram_checker is a boolean comparator: \n", " True if the two strings are anagrams; False if the two strings are not anagrams.\n", - " Print message to inddicate whether the two strings are anagrams. '''\n", + " Assume uppercase letters are interchangeable with lowercase letters; therefore, \n", + " convert all string characters to lower case before comparing string equivalence. \n", + " '''\n", " \n", - " # Perform an ascending sort of the characters contained in both string arguments\n", - " word1 = 'word_a'\n", - " sorted_word1 = sorted(word1)\n", - " word2 = 'word_b'\n", - " sorted_word2 = sorted(word2)\n", + "# Assign the function string parameters to a lowercase variable\n", + " word1 = word_a.lower()\n", + " word2 = word_b.lower()\n", "\n", - " # Print the two sorted string lists \n", - " print('String one: ', sorted_word1)\n", - " print('String two: ', sorted_word2)\n", + "# Perform an ascending sort of the characters contained in both string variables\n", + " sorted_word1 = sorted(str(word1))\n", + " sorted_word2 = sorted(str(word2))\n", "\n", - " # Perform a boolean comparison and print the result\n", - " if word1 == word2:\n", - " print('The two strings are anagrams of each other')\n", - " else:\n", - " print('The two strings are not anagrams.')\n", + "# Perform a boolean equivalence comparison for the two strings\n", + " return sorted_word1 == sorted_word2\n", "\n", "# Run your code to check using the words below:\n", "anagram_checker(\"Silent\", \"listen\")" @@ -102,7 +99,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 45, "metadata": {}, "outputs": [ { @@ -111,7 +108,7 @@ "False" ] }, - "execution_count": 46, + "execution_count": 45, "metadata": {}, "output_type": "execute_result" } @@ -122,7 +119,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 46, "metadata": {}, "outputs": [ { @@ -131,7 +128,7 @@ "True" ] }, - "execution_count": 47, + "execution_count": 46, "metadata": {}, "output_type": "execute_result" } @@ -153,22 +150,66 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 56, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def anagram_checker(word_a, word_b, is_case_sensitive):\n", " # Modify your existing code here\n", + " ''' Given two valid strings, check if they are anagrams.\n", + " anagram_checker is a boolean comparator: \n", + " True if the two strings are anagrams; False if the two strings are not anagrams.\n", + " word_a is the first string parameter.\n", + " word_b is the second string parameter.\n", + " is_case_sensitive is a boolean option, indicating whether case sensitivity is important:\n", + " (a) True, include the sorted.() function str.casefold to sort string alphabetically, regardless of case.\n", + " (b) False, use existing Part 1 code to sort the string alphabetically, fixing stricng characters as lower case. \n", + " ''' \n", + "# Assign the function string parameters to a function variable\n", + " word1 = word_a\n", + " word2 = word_b\n", + " # Conditional on whether case sensitivity is True or False and perform an ascending sort of the characters contained in both string arguments\n", + " if is_case_sensitive:\n", + " # Assign the two function string parameters to a function variable\n", + " sorted_word1 = sorted(str(word1), key=str.casefold)\n", + " sorted_word2 = sorted(str(word2), key=str.casefold)\n", + " else:\n", + " word1 = word_a.lower()\n", + " word2 = word_b.lower()\n", + " sorted_word1 = sorted(str(word1))\n", + " sorted_word2 = sorted(str(word2))\n", + " return sorted_word1 == sorted_word2\n", "\n", - " \n", "\n", "# Run your code to check using the words below:\n", - "anagram_checker(\"Silent\", \"listen\", False) # True" + "anagram_checker(\"Silent\", \"listen\", False) # True\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 57, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 57, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"Silent\", \"Listen\", True) # False" ] From 958d85433107597b77e74a295c853870eaa86dab Mon Sep 17 00:00:00 2001 From: Ceci Date: Sun, 19 Oct 2025 17:10:11 -0400 Subject: [PATCH 3/4] Edited part 2 docstring --- 02_activities/assignments/assignment_1.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index 8b118044f..a4b75ee57 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -171,8 +171,8 @@ " word_a is the first string parameter.\n", " word_b is the second string parameter.\n", " is_case_sensitive is a boolean option, indicating whether case sensitivity is important:\n", - " (a) True, include the sorted.() function str.casefold to sort string alphabetically, regardless of case.\n", - " (b) False, use existing Part 1 code to sort the string alphabetically, fixing stricng characters as lower case. \n", + " (a) True, include the sorted.() function optional key str.casefold parameter to sort string alphabetically, regardless of case.\n", + " (b) False, use existing Part 1 code to sort the string alphabetically, fixing string characters as lower case. \n", " ''' \n", "# Assign the function string parameters to a function variable\n", " word1 = word_a\n", From e164ec8d4225f8b70fd64f5b9327737c90d645d4 Mon Sep 17 00:00:00 2001 From: Ceci Date: Sun, 19 Oct 2025 17:14:18 -0400 Subject: [PATCH 4/4] Modified Part 2 docstring for readability --- 02_activities/assignments/assignment_1.ipynb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index a4b75ee57..79ed06472 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -171,7 +171,8 @@ " word_a is the first string parameter.\n", " word_b is the second string parameter.\n", " is_case_sensitive is a boolean option, indicating whether case sensitivity is important:\n", - " (a) True, include the sorted.() function optional key str.casefold parameter to sort string alphabetically, regardless of case.\n", + " (a) True, include the sorted.() function optional key str.casefold parameter to sort string alphabetically, \n", + " regardless of case.\n", " (b) False, use existing Part 1 code to sort the string alphabetically, fixing string characters as lower case. \n", " ''' \n", "# Assign the function string parameters to a function variable\n",