diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index 156d0408e..292fd6992 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -56,13 +56,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# For testing purposes, we will write our code in the function\n", + " # first you need to normalice the values (all the characters in each word could be loweers)\n", + " # Second you need to delete the spacies, just in case the anagram has more than 1 word, in this case I replaced the space ' ' with '' an empty value.\n", + " # third after normalize the characters and delete the spaces you can sorted the characters in alphabetic order\n", + " # Finaly you compare the result. \n", + "\n", "def anagram_checker(word_a, word_b):\n", - " # Your code here\n", + " word_a_list = sorted (word_a.lower().replace(' ', '')) \n", + " word_b_list = sorted (word_b.lower().replace(' ', '')) \n", + " return word_a_list == word_b_list\n", + "\n", "\n", "# Run your code to check using the words below:\n", "anagram_checker(\"Silent\", \"listen\")" @@ -70,18 +89,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"Silent\", \"Night\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"night\", \"Thing\")" ] @@ -97,24 +138,54 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "def anagram_checker(word_a, word_b, is_case_sensitive):\n", - " # Modify your existing code here\n", - "\n", + "def anagram_checker_sensitive (word_a, word_b, is_case_sensitive):\n", + " # first define if not is_case_sensitive: normalized characters and compare the words without spaces and in lowers.\n", + " if not is_case_sensitive:\n", + " word_a_list = sorted (word_a.lower().replace(' ', ''))\n", + " word_b_list = sorted (word_b.lower().replace(' ', ''))\n", + " return word_a_list == word_b_list\n", + " \n", + " #second: define if is_case_sensitive, not normalized the characters, remove the spaces and sorted to compare the list between the two words.\n", + " elif is_case_sensitive:\n", + " return sorted (word_a.replace(' ', ''))== sorted(word_b.replace(' ', ''))\n", + " \n", "# Run your code to check using the words below:\n", - "anagram_checker(\"Silent\", \"listen\", False) # True" + "anagram_checker_sensitive (\"Silent\", \"listen\", False) # True" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "anagram_checker(\"Silent\", \"Listen\", True) # False" + "anagram_checker_sensitive (\"Silent\", \"Listen\", True) # False" ] }, { @@ -130,7 +201,7 @@ ], "metadata": { "kernelspec": { - "display_name": "new-learner", + "display_name": "dsi_participant", "language": "python", "name": "python3" }, @@ -144,7 +215,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.9.18" } }, "nbformat": 4,