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
106 changes: 96 additions & 10 deletions 02_assignments/assignment_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,81 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 139,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 139,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# This is a function, which we will learn more about next week. 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",
" word_a = word_a.lower()\n",
" word_b = word_b.lower()\n",
" \n",
" if len(word_a) == len(word_b):\n",
" sorted_word_a = sorted(word_a)\n",
" sorted_word_a = ''.join(sorted_word_a)\n",
"\n",
" sorted_word_b = sorted(word_b)\n",
" sorted_word_b = ''.join(sorted_word_b)\n",
" if sorted_word_a == sorted_word_b:\n",
" return True\n",
" else:\n",
" return False\n",
" else:\n",
" return False\n",
" \n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Slient\", \"listen\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 140,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 140,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Slient\", \"Night\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 141,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 141,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"night\", \"Thing\")"
]
Expand All @@ -97,22 +146,59 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 142,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 142,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def anagram_checker(word_a, word_b, is_case_sensitive):\n",
" # Modify your existing code here\n",
" if is_case_sensitive == False:\n",
" word_a = word_a.lower()\n",
" word_b = word_b.lower()\n",
" \n",
" if len(word_a) == len(word_b):\n",
" sorted_word_a = sorted(word_a)\n",
" sorted_word_a = ''.join(sorted_word_a)\n",
"\n",
" sorted_word_b = sorted(word_b)\n",
" sorted_word_b = ''.join(sorted_word_b)\n",
" if sorted_word_a == sorted_word_b:\n",
" return True\n",
" else:\n",
" return False\n",
" else:\n",
" return False \n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Slient\", \"listen\", False) # True"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 143,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 143,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Slient\", \"Listen\", True) # False"
]
Expand Down