Skip to content
Open
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
124 changes: 108 additions & 16 deletions 02_activities/assignments/assignment_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,81 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 16,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 16,
"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",
"def anagram_checker(word_a: str, word_b: str) -> bool:\n",
" '''\n",
" - This function checks if word_a and word_b are anagrams of each other\n",
" - Anagrams are words or phrases that can be rearranged to make an entirely different word or phrase.\n",
" - with all the original letters \n",
" Args:\n",
" word_a : str, a word or phrase\n",
" word_b : str, words or phrases that can be rearranged to make an entirely different \n",
" returns:\n",
" boolean: if word_a and word_b are anagrams returns True otherwise False \n",
" \n",
" '''\n",
" # Your code here\n",
" # convert the upper case to lower case\n",
" # For phrases remove the space\n",
" word_a, word_b = word_a.replace(' ', '').lower(), word_b.replace(' ', '').lower()\n",
" return sorted(word_a) == sorted(word_b)\n",
"\n",
"\n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Silent\", \"listen\")"
"anagram_checker(\"Silent\", \"listen\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 17,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Silent\", \"Night\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"night\", \"Thing\")"
]
Expand All @@ -99,20 +148,63 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def anagram_checker(word_a, word_b, is_case_sensitive):\n",
" # Modify your existing code here\n",
"# def anagram_checker(word_a, word_b, is_case_sensitive):\n",
"# # Modify your existing code here\n",
"\n",
"# 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: str, word_b: str, is_case_sensitive: bool) -> bool:\n",
" # Modify your existing code here\n",
" '''\n",
" - This function checks if word_a and word_b are anagrams of each other\n",
" - Anagrams are words or phrases that can be rearranged to make an entirely different word or phrase.\n",
" - with all the original letters \n",
" Args:\n",
" word_a : str, a word or phrase\n",
" word_b : str, words or phrases that can be rearranged to make an entirely different \n",
" is_case_sensitive: boolean, If True, the comparison is case-sensitive. \n",
" returns:\n",
" boolean: if word_a and word_b are anagrams returns True otherwise False \n",
" \n",
" '''\n",
" # convert the upper case to lower case\n",
"\n",
" if not is_case_sensitive:\n",
" word_a, word_b = word_a.replace(' ', '').lower(), word_b.replace(' ', '').lower()\n",
" return sorted(word_a) == sorted(word_b)\n",
"\n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Silent\", \"listen\", False) # True"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Silent\", \"Listen\", True) # False"
]
Expand All @@ -130,7 +222,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "new-learner",
"display_name": "dsi_participant",
"language": "python",
"name": "python3"
},
Expand All @@ -144,7 +236,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.9.15"
}
},
"nbformat": 4,
Expand Down
Loading