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
107 changes: 89 additions & 18 deletions 02_activities/assignments/assignment_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,73 @@
},
{
"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\")"
]
},
{
"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\")"
]
Expand All @@ -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"
]
},
{
Expand All @@ -130,7 +201,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "new-learner",
"display_name": "dsi_participant",
"language": "python",
"name": "python3"
},
Expand All @@ -144,7 +215,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.9.18"
}
},
"nbformat": 4,
Expand Down