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
125 changes: 112 additions & 13 deletions 02_activities/assignments/assignment_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,86 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"\n",
"# 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",
" ''' Given input strings, word_a and word_b, returns True if the words are anagrams, and \n",
" False if they are not\n",
" Input:\n",
" word_a: str, strings of letters\n",
" word_b: str, strings of letters\n",
" Output:\n",
" bool\n",
" '''\n",
" ## Put both strings in the same case\n",
" word_a = word_a.lower()\n",
" word_b = word_b.lower()\n",
"\n",
" ## Changes both strings into lists of 1 letter strings, and sorts them\n",
" letter_list_a = sorted(list(word_a))\n",
" letter_list_b = sorted(list(word_b))\n",
"\n",
" ## checks if each of these sorted letter lists are equal and returns boolean\n",
" return(letter_list_a == letter_list_b)\n",
"\n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Silent\", \"listen\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Silent\", \"Night\")"
]
},
{
"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": [
"anagram_checker(\"night\", \"Thing\")"
]
Expand All @@ -97,22 +151,67 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 17,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def anagram_checker(word_a, word_b, is_case_sensitive):\n",
" # Modify your existing code here\n",
" # Your code here\n",
"\n",
" '''Given input strings, word_a and word_b, returns True if the words are anagrams, and \n",
" False if they are not. Can choose to only accept anagrams where all cases match with is_case_sensitive\n",
" Input:\n",
" word_a: str, strings of letters\n",
" word_b: str, strings of letters\n",
" is_case_sensitive: bool, if true, only checks for anagrams where all cases match\n",
" Output:\n",
" bool\n",
" '''\n",
"\n",
" ## Put both strings in the same case if is_case_sensitive is False\n",
" if is_case_sensitive == False:\n",
" word_a = word_a.lower()\n",
" word_b = word_b.lower()\n",
"\n",
" ## Changes both strings into lists of 1 letter strings, and sorts them\n",
" letter_list_a = sorted(list(word_a))\n",
" letter_list_b = sorted(list(word_b))\n",
"\n",
" ## checks if each of these sorted letter lists are equal and returns boolean\n",
" return(letter_list_a == letter_list_b)\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": 18,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Silent\", \"Listen\", True) # False"
]
Expand All @@ -130,7 +229,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "new-learner",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -144,7 +243,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.10.10"
}
},
"nbformat": 4,
Expand Down
Loading