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
133 changes: 120 additions & 13 deletions 02_activities/assignments/assignment_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,87 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 50,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 50,
"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",
" # switching to Lower case letters for both words\n",
" word_a_lower = word_a.lower()\n",
" word_b_lower = word_b.lower()\n",
" \n",
" # Changing the type from String to List for both words\n",
" word_a_lower_list = list(word_a_lower)\n",
" word_b_lower_list = list(word_b_lower)\n",
" \n",
" # print(word_a_l_list)\n",
" # print(word_b_l_list)\n",
"\n",
" # Sorting word_a_lower & word_b_lower per alphapetic, Result: The original list will be sorted\n",
" word_a_lower_list.sort()\n",
" word_b_lower_list.sort()\n",
"\n",
" # print(word_a_l_list)\n",
" # print(word_b_l_list)\n",
"\n",
" # Comparing the sorted words to see if they are equal(ANAGRAM)?\n",
" if (word_a_lower_list == word_b_lower_list):\n",
" return True\n",
" else:\n",
" return False\n",
" \n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Silent\", \"listen\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 51,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Silent\", \"Night\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 52,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"night\", \"Thing\")"
]
Expand All @@ -97,22 +152,74 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 53,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def anagram_checker(word_a, word_b, is_case_sensitive):\n",
" # Modify your existing code here\n",
" # Check if Case Sensitive required?\n",
" if is_case_sensitive :\n",
" # Keep Letters as they are ( No case changing)\n",
" word_a = word_a\n",
" word_b = word_b\n",
" # Changing the type from String to List for both words A & B\n",
" word_a_list = list(word_a)\n",
" word_b_list = list(word_b) \n",
" else:\n",
" # switching to Lower case letters for both words\n",
" word_a_l = word_a.lower()\n",
" word_b_l = word_b.lower()\n",
" # Changing the type from String to List for both words A & B\n",
" word_a_list = list(word_a_l)\n",
" word_b_list = list(word_b_l)\n",
" \n",
" # print(word_a_list)\n",
" # print(word_b_list)\n",
"\n",
" # Sorting word_a_l & word_b_l per alphapetic, Result: The original list will be sorted\n",
" word_a_list.sort()\n",
" word_b_list.sort()\n",
"\n",
" # print(word_a_list)\n",
" # print(word_b_list)\n",
"\n",
" # Comparing the sorted words to see if they are equal(ANAGRAM)?\n",
" if (word_a_list == word_b_list):\n",
" return True\n",
" else:\n",
" return False\n",
"\n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Silent\", \"listen\", False) # True"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 45,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Silent\", \"Listen\", True) # False"
]
Expand Down Expand Up @@ -144,7 +251,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.12.3"
}
},
"nbformat": 4,
Expand Down