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
109 changes: 92 additions & 17 deletions 02_activities/assignments/assignment_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,55 @@
"outputs": [],
"source": [
"# 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",
"# PLEASE NOTE THAT I HAVE DELIBERATELY WRITTEN A LONG AND DETAILED CODE FOR PRACTICE\n",
"# I will use print for Part 1 and return for Part 2\n",
"def anagram_checker(word_a, word_b):\n",
" # Convert word_a and word_b to a uniform case.\n",
" upper_word_a = word_a.upper()\n",
" upper_word_b = word_b.upper()\n",
" # Sort the letters of each word alphabetically and compare. Return the boolean result.\n",
" return(sorted(upper_word_a) == sorted(upper_word_b))\n",
" \n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Silent\", \"listen\")"
"# anagram_checker(\"Silent\", \"listen\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 21,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Silent\", \"Night\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 22,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"night\", \"Thing\")"
]
Expand All @@ -97,26 +125,73 @@
},
{
"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",
"# Run your code to check using the words below:\n",
" # Below will apply if not case sensitive.\n",
" if is_case_sensitive == False:\n",
" upper_word_a = word_a.upper()\n",
" upper_word_b = word_b.upper()\n",
" return(sorted(upper_word_a)==sorted(upper_word_b))\n",
" else:\n",
" # Below will apply if case sensitive.\n",
" return(sorted(word_a) == sorted(word_b))\n",
"anagram_checker(\"Silent\", \"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(\"Silent\", \"Listen\", True) # False"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n",
"True\n"
]
}
],
"source": [
"# Checking our function for another set of words\n",
"print(anagram_checker('Verse', 'Serve', True))\n",
"print(anagram_checker('Verse', 'serve', False))"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -130,7 +205,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "new-learner",
"display_name": "dsi_participant",
"language": "python",
"name": "python3"
},
Expand All @@ -144,7 +219,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.9.18"
}
},
"nbformat": 4,
Expand Down