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
131 changes: 121 additions & 10 deletions 02_activities/assignments/assignment_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,85 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 25,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 25,
"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",
" Given two valid strings, check to see if they are anagrams of each other. If it is, return `True`, else `False`. \n",
" Uppercase letters are treated the same as if it was a lowercase character.\n",
"\n",
" Parameters:\n",
" `word_a`: Any valid string.\n",
" `word_b`: Another valid string.\n",
" \n",
" Returns:\n",
" Boolean based on if the two compared words are anagrams. \n",
" '''\n",
" \n",
" # Create a new list containing a sorted version of each string and convert to lower case.\n",
" word_a_sorted = sorted(word_a.lower())\n",
" word_b_sorted = sorted(word_b.lower())\n",
"\n",
" if word_a_sorted == word_b_sorted:\n",
" return True\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": 26,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Slient\", \"Night\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 27,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"night\", \"Thing\")"
]
Expand All @@ -97,22 +150,80 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 28,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def anagram_checker(word_a, word_b, is_case_sensitive):\n",
" # Modify your existing code here\n",
" '''\n",
" Given two valid strings, check to see if they are anagrams of each other. If it is, return `True`, else `False`. \n",
" This function checks for case sensitivity based on the third parameter is_case_sensitive.\n",
"\n",
" Parameters:\n",
" `word_a`: Any valid string.\n",
" `word_b`: Another valid string.\n",
" `is_case_sensitive`: Boolean that specifies if the function will check for case sensitivity.\n",
" \n",
" Returns:\n",
" Boolean based on if the two compared words are anagrams.\n",
" '''\n",
" \n",
" if is_case_sensitive == False:\n",
" # Create a new list containing a sorted version of each string and convert to lower case.\n",
" word_a_sorted = sorted(word_a.lower())\n",
" word_b_sorted = sorted(word_b.lower())\n",
"\n",
" if word_a_sorted == word_b_sorted:\n",
" return True\n",
" else:\n",
" return False\n",
" \n",
" elif is_case_sensitive == True:\n",
" # Create a new list containing a sorted version of each string without converting to lower case.\n",
" word_a_sorted = sorted(word_a)\n",
" word_b_sorted = sorted(word_b)\n",
"\n",
" if word_a_sorted == word_b_sorted:\n",
" return True\n",
" else:\n",
" return False\n",
" \n",
" else: \n",
" raise ValueError(\"Invalid parameter. Please choose True or False\")\n",
"\n",
"\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": 29,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Slient\", \"Listen\", True) # False"
]
Expand Down