Skip to content
Closed

test #72

Show file tree
Hide file tree
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
299 changes: 283 additions & 16 deletions 02_assignments/assignment_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,34 +56,138 @@
},
{
"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": [
"# 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",
" \"\"\" Check if two words or phrases are anagrams \"\"\" \n",
" # An anagram is a word or phrase formed \n",
" # by rearranging the letters of another word or phrase\n",
" \n",
" # Remove non-alphabetic characters from the input words \n",
" word_a = ''.join(char for char in word_a.lower() if char.isalpha())\n",
" word_b = ''.join(char for char in word_b.lower() if char.isalpha())\n",
" \n",
" # Check if the sorted characters in the words are the same\n",
" return sorted(word_a) == sorted(word_b)\n",
"\n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Slient\", \"listen\")"
"anagram_checker(\" Slient\", \"listen\") # True"
]
},
{
"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(\"Slient\", \"Night\")"
"anagram_checker(\"Slient\", \"Night\") # False"
]
},
{
"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\")"
"anagram_checker(\"night\", \"Thing\") # True"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Anagram phrases with spaces\n",
"anagram_checker(\"salvages\", \"Las Vegas\") # True"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Anagram phrases with spaces and punctulation\n",
"anagram_checker(\"the public art galleries\", \"large picture halls, I bet\") #\tTrue"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"asdflkasdjf , 2302, 13 ; /-\", \"gibberish\") #\tFalse"
]
},
{
Expand All @@ -97,26 +201,184 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 7,
"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 two words are anagrams with the case sensitive parameter \"\"\"\n",
" \n",
" # Remove non-alphabetic characters from the input words \n",
" word_a = ''.join(char for char in word_a if char.isalpha())\n",
" word_b = ''.join(char for char in word_b if char.isalpha())\n",
" \n",
" # If is_case_sensitive is True, Sort the words not converting to lowercase and compare them \n",
" if is_case_sensitive: \n",
" return sorted(word_a) == sorted(word_b) \n",
" \n",
" # If is_case_sensitive is False, convert both words to lists in lowercase and compare them\n",
" else:\n",
" return sorted(word_a.lower()) == sorted(word_b.lower()) \n",
" \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": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Iceman\", \"Cimena\", True) # False"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# anagram-phrases with spaces\n",
"anagram_checker(\"the Morse Code\", \"here come dots\", False) # True"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# phrases with spaces, punctuation, and capitalization\n",
"anagram_checker(\"departed this life\", \"He's left it, dead RIP\", False) # True"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"pairs\", \"Paris\", True) # False"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"dormitory\", \"dirty room\", False) # True"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Slient\", \"Listen\", True) # False"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Q!W@E#r4t5y6789\", \"Q!W@E#r,,,4//%^&*()t 5 y ;:6### 7 8-9\", False) # True"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -126,6 +388,11 @@
"|Code Execution|All code cells execute without errors.|Any code cell produces an error upon execution.|\n",
"|Code Quality|Code is well-organized, concise, and includes necessary comments for clarity. E.g. Great use of variable names.|Code is unorganized, verbose, or lacks necessary comments. E.g. Single character variable names outside of loops.|"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {
Expand All @@ -144,7 +411,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.9.15"
}
},
"nbformat": 4,
Expand Down
Loading