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
140 changes: 128 additions & 12 deletions 02_activities/assignments/assignment_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,43 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"It is an anagram : silent listen\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# For testing purposes, we will write our code in the function\n",
"from collections import Counter\n",
"def anagram_checker(word_a, word_b):\n",
"\n",
" word_b = str.lower(word_b)\n",
" word_a = str.lower(word_a)\n",
" if (len(word_a) != len(word_b) ):\n",
" print('not an anagram')\n",
" return False\n",
" if Counter(word_b) == Counter(word_a):\n",
" print('It is an anagram :', word_a, word_b)\n",
" return True\n",
" else:\n",
" print('Not an anagram')\n",
" return False\n",
" # Your code here\n",
"\n",
"# Run your code to check using the words below:\n",
Expand All @@ -70,18 +101,54 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"not an anagram\n"
]
},
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Silent\", \"Night\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"It is an anagram night thing\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"night\", \"Thing\")"
]
Expand All @@ -97,11 +164,42 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"It is an anagram : silent listen\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from collections import Counter\n",
"def anagram_checker(word_a, word_b, is_case_sensitive):\n",
" if(is_case_sensitive == False):\n",
" word_b = str.lower(word_b)\n",
" word_a = str.lower(word_a)\n",
" if (len(word_a) != len(word_b) ):\n",
" print('not an anagram')\n",
" return False\n",
" if Counter(word_b) == Counter(word_a):\n",
" print('It is an anagram :', word_a, word_b)\n",
" return True\n",
" else:\n",
" print('Not an anagram')\n",
" return False\n",
" # Modify your existing code here\n",
"\n",
"# Run your code to check using the words below:\n",
Expand All @@ -110,9 +208,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Not an anagram\n"
]
},
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Silent\", \"Listen\", True) # False"
]
Expand All @@ -130,7 +246,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "new-learner",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -144,7 +260,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.11.3"
}
},
"nbformat": 4,
Expand Down
Loading