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
129 changes: 115 additions & 14 deletions 02_activities/assignments/assignment_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,83 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"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",
" '''Check to see if two valid strings are anagrams of each other.\n",
" \n",
" Parameters: \n",
" word_a, word_b. \n",
" \n",
" Arguments: \n",
" word_a.lower(): The first string converted to lowercase to handle case insensitivity.\n",
" word_b.lower(): The second string converted to lowercase to handle case insensitivity.\n",
"\n",
" sorted() function:\n",
" Sorts characters in the lowercase strings alphabetically based on their Unicode code point value.\n",
"\n",
" Returns:\n",
" Boolean: True if the two strings are anagrams of each other (sorted characters are equal), False otherwise.'''\n",
" if sorted(word_a.lower()) == sorted(word_b.lower()):\n",
" return True\n",
" else:\n",
" return False\n",
" \n",
"\n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Silent\", \"listen\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Silent\", \"Night\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"night\", \"Thing\")"
]
Expand All @@ -97,22 +148,72 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Modify existing code to add a boolean option called is_case_sensitive for case sensitivity\n",
"def anagram_checker(word_a, word_b, is_case_sensitive):\n",
" # Modify your existing code here\n",
" '''Check to see if two valid strings are anagrams of each other and add a boolean option to check for case sensitivity.\n",
" \n",
" Parameters: \n",
" word_a, word_b, is_case_sensitive.\n",
" \n",
" Arguments: \n",
" word_a: The first string (converted to lowercase with .lower()).\n",
" word_b: The second string (converted to lowercase with .lower()).\n",
" is_case_sensitive: A boolean option where True indicates we are checking for case sensitivity (the strings can only be equal if each character is in the same case) and False indicates we are not checking for case sensitivity.\n",
"\n",
" sorted() function:\n",
" Sorts characters in the strings alphabetically based on their Unicode code point value.\n",
"\n",
" Returns:\n",
" Boolean: True or False based on if the two strings are anagrams of each other and if we are checking for case sensitivity.'''\n",
" if sorted(word_a) == sorted(word_b):\n",
" if is_case_sensitive:\n",
" return True\n",
" else:\n",
" return False\n",
" elif sorted(word_a.lower()) == sorted(word_b.lower()):\n",
" if is_case_sensitive:\n",
" return False\n",
" else:\n",
" return True\n",
" else:\n",
" return False\n",
"\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": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Silent\", \"Listen\", True) # False"
]
Expand All @@ -130,7 +231,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "new-learner",
"display_name": "python-env",
"language": "python",
"name": "python3"
},
Expand All @@ -144,7 +245,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.11.13"
}
},
"nbformat": 4,
Expand Down