Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 50 additions & 5 deletions 02_activities/assignments/assignment_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,27 @@
"# 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",
"# Run your code to check using the words below:\n",
" if len(word_a) != len(word_b):\n",
" return False\n",
" # The number of characters in the strings need to match or it's not an anagram for sure\n",
" else:\n",
" word_a_converted = word_a.lower()\n",
" word_b_converted = word_b.lower()\n",
" # Convert both the string to lower case to avoid case sensitivity, then move on to check for anagram\n",
" if sorted(word_a_converted) == sorted(word_b_converted):\n",
" return True\n",
" else:\n",
" return False\n",
" # Sort both string by characters to check whether they are anagram or not\n",
"# Run your code to check using the words below:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"anagram_checker(\"Silent\", \"listen\")"
]
},
Expand Down Expand Up @@ -103,8 +122,34 @@
"source": [
"def anagram_checker(word_a, word_b, is_case_sensitive):\n",
" # Modify your existing code here\n",
" if len(word_a) != len(word_b):\n",
" return False\n",
" else:\n",
" if is_case_sensitive == True:\n",
" # If the the input is true for case sensitivity, skips the step to convert both strings into lower case and just compare them after sorting\n",
" if sorted(word_a) == sorted(word_b):\n",
" return True\n",
" else:\n",
" return False\n",
"\n",
"# Run your code to check using the words below:\n",
" if is_case_sensitive == False:\n",
" # If the input is false for case sensitivity, repeat the code from the previous part\n",
" word_a_converted = word_a.lower()\n",
" word_b_converted = word_b.lower()\n",
"\n",
" if sorted(word_a_converted) == sorted(word_b_converted):\n",
" return True\n",
" else:\n",
" return False \n",
"# Run your code to check using the words below:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"anagram_checker(\"Silent\", \"listen\", False) # True"
]
},
Expand Down Expand Up @@ -139,7 +184,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "new-learner",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -153,7 +198,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.11.14"
}
},
"nbformat": 4,
Expand Down