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
49 changes: 43 additions & 6 deletions 02_activities/assignments/assignment_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,37 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "AttributeError",
"evalue": "'str' object has no attribute 'symmetric_difference'",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mAttributeError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[3]\u001b[39m\u001b[32m, line 17\u001b[39m\n\u001b[32m 12\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[33m'\u001b[39m\u001b[33mFalse\u001b[39m\u001b[33m'\u001b[39m)\n\u001b[32m 16\u001b[39m \u001b[38;5;66;03m# Run your code to check using the words below:\u001b[39;00m\n\u001b[32m---> \u001b[39m\u001b[32m17\u001b[39m \u001b[43managram_checker\u001b[49m\u001b[43m(\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mSilent\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mlisten\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[3]\u001b[39m\u001b[32m, line 7\u001b[39m, in \u001b[36managram_checker\u001b[39m\u001b[34m(word_a, word_b)\u001b[39m\n\u001b[32m 5\u001b[39m {word_b}\n\u001b[32m 6\u001b[39m \u001b[38;5;66;03m# we want to then see all values only in one of two sets\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m7\u001b[39m \u001b[43mword_a\u001b[49m\u001b[43m.\u001b[49m\u001b[43msymmetric_difference\u001b[49m(word_b)\n\u001b[32m 8\u001b[39m \u001b[38;5;66;03m# if symmatric_difference is True then we want to print True and if False then we print False \u001b[39;00m\n\u001b[32m 9\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m word_a.symmetric_difference(word_b) == \u001b[38;5;28mset\u001b[39m(): \n",
"\u001b[31mAttributeError\u001b[39m: 'str' object has no attribute 'symmetric_difference'"
]
}
],
"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",
" # first we need to make into a set \n",
" {word_a}\n",
" {word_b}\n",
" # we want to then see all values only in one of two sets\n",
" word_a.symmetric_difference(word_b)\n",
" # if symmatric_difference is True then we want to print True and if False then we print False \n",
" if word_a.symmetric_difference(word_b) == set(): \n",
" print('True')\n",
" if word_a.symmetric_difference(word_b) != set(): \n",
" print('False')\n",
"\n",
"\n",
"\n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Silent\", \"listen\")"
Expand Down Expand Up @@ -102,7 +126,20 @@
"outputs": [],
"source": [
"def anagram_checker(word_a, word_b, is_case_sensitive):\n",
" # Modify your existing code here\n",
" # first we need to make into a set \n",
" {word_a}\n",
" {word_b}\n",
" # we want to then see all values only in one of two sets \n",
" word_a.symmetric_difference(word_b)\n",
" # if symmetric_difference is True then we want to print True and if False then we print False \n",
" if word_a.symmetric_difference(word_b) == set(): \n",
" print('True')\n",
" if word_a.symmetric_difference(word_b) != set(): \n",
" print('False')\n",
" if not is_case_sensitive: \n",
" print('True')\n",
" if is_case_sensitive:\n",
" print('False')\n",
"\n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Silent\", \"listen\", False) # True"
Expand Down Expand Up @@ -139,7 +176,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "new-learner",
"display_name": "python-env (3.11.14)",
"language": "python",
"name": "python3"
},
Expand All @@ -153,7 +190,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.11.14"
}
},
"nbformat": 4,
Expand Down