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
87 changes: 78 additions & 9 deletions 02_activities/assignments/assignment_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,39 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# For testing purposes, we will write our code in the function\n",
"# Your code here\n",
" # Normally I would prepare this as a looping input to have user the input two words and to reject non-words, phrases, etc.\n",
" # I understand you are seeking something more basic.\n",
" # Here are my algorithmis steps:\n",
" # convert the words to lower case - use: .lower()\n",
" # reorganize the letters in the word alphabetically - use: sorted()\n",
" # reassign alphabetized \"words\" to new lower case, sorted variables\n",
" # compare the new lower case, sorted variables\n",
" # \n",
"\n",
"def anagram_checker(word_a, word_b):\n",
" # Your code here\n",
" '''a function designed to check whether two words are anagrams'''\n",
" word_a_lower = word_a.lower()\n",
" word_b_lower = word_b.lower() \n",
" word_a_sorted = sorted(word_a_lower)\n",
" word_b_sorted = sorted(word_b_lower) \n",
"\n",
" result = word_a_sorted == word_b_sorted\n",
" return (result)\n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Silent\", \"listen\")"
]
Expand Down Expand Up @@ -97,26 +124,68 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 30,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def anagram_checker(word_a, word_b, is_case_sensitive):\n",
" # Modify your existing code here\n",
" '''a function designed to check whether two words are case-sensitive anagrams'''\n",
" if is_case_sensitive:\n",
" # word_a_lower = word_a.lower() - this is not needed if it's case sensitive\n",
" # word_b_lower = word_b.lower() - this is not needed if it's case sensitive \n",
" word_a_sorted = sorted(word_a)\n",
" word_b_sorted = sorted(word_b)\n",
" else:\n",
" word_a_lower = word_a.lower()\n",
" word_b_lower = word_b.lower() \n",
" word_a_sorted = sorted(word_a_lower)\n",
" word_b_sorted = sorted(word_b_lower) \n",
"\n",
" result = word_a_sorted == word_b_sorted\n",
" return (result)\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": 31,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Silent\", \"Listen\", True) # False"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -130,7 +199,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "new-learner",
"display_name": "dsi_participant",
"language": "python",
"name": "python3"
},
Expand All @@ -144,7 +213,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.9.18"
}
},
"nbformat": 4,
Expand Down