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
36 changes: 30 additions & 6 deletions 02_activities/assignments/assignment_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,18 @@
"source": [
"# For testing purposes, we will write our code in the function\n",
"def anagram_checker(word_a, word_b):\n",
" '''\n",
" Checks whether two valid strings (word_a and word_b) are anagrams of each other\n",
" Returns True if anagram and False if not\n",
" '''\n",
" # Your code here\n",
" if sorted(word_a.lower()) == sorted(word_b.lower()):\n",
" return True\n",
" else:\n",
" return False\n",
"\n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Silent\", \"listen\")"
"anagram_checker(\"Silent\", \"listen\") # True"
]
},
{
Expand All @@ -74,7 +82,7 @@
"metadata": {},
"outputs": [],
"source": [
"anagram_checker(\"Silent\", \"Night\")"
"anagram_checker(\"Silent\", \"Night\") # False"
]
},
{
Expand All @@ -83,7 +91,7 @@
"metadata": {},
"outputs": [],
"source": [
"anagram_checker(\"night\", \"Thing\")"
"anagram_checker(\"night\", \"Thing\") # True"
]
},
{
Expand All @@ -102,7 +110,23 @@
"outputs": [],
"source": [
"def anagram_checker(word_a, word_b, is_case_sensitive):\n",
" # Modify your existing code here\n",
" '''\n",
" Checks whether two valid strings (word_a and word_b) are anagrams of each other\n",
" Returns True if anagram and False if not\n",
" Includes boolean option is_case_sensitive\n",
" '''\n",
" if is_case_sensitive:\n",
" # case sensitive\n",
" if sorted(word_a) == sorted(word_b):\n",
" return True\n",
" else:\n",
" return False\n",
" else:\n",
" # not case sensitive\n",
" if sorted(word_a.lower()) == sorted(word_b.lower()):\n",
" return True\n",
" else:\n",
" return False\n",
"\n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Silent\", \"listen\", False) # True"
Expand Down Expand Up @@ -130,7 +154,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "new-learner",
"display_name": "python-env (3.11.13)",
"language": "python",
"name": "python3"
},
Expand All @@ -144,7 +168,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.11.13"
}
},
"nbformat": 4,
Expand Down