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
45 changes: 43 additions & 2 deletions 02_assignments/assignment_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,23 @@
"outputs": [],
"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",
"\n",
"# The function is to check if an anagram for two input words regardless the case\n",
"def anagram_checker(word_a, word_b):\n",
" # Your code here\n",
" # Initial check if any empty string or different string length\n",
" if (len(word_a) < 1 or len(word_b) < 1 or len(word_a) != len(word_b)):\n",
" #print (\"False\")\n",
" return False\n",
" else:\n",
" #print (sorted(word_a.lower()))\n",
" #print (sorted(word_b.lower()))\n",
" # To lower the case and sort the letters for comparision\n",
" if sorted(word_a.lower()) == sorted(word_b.lower()):\n",
" #print (\"True\")\n",
" return True\n",
" else:\n",
" #print (\"False\")\n",
" return False\n",
"\n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Slient\", \"listen\")"
Expand Down Expand Up @@ -101,8 +116,34 @@
"metadata": {},
"outputs": [],
"source": [
"# The function is with the option of case sensitive to check if an anagram for two input words\n",
"def anagram_checker(word_a, word_b, is_case_sensitive):\n",
" # Modify your existing code here\n",
" # Initial check if any empty string or different string length\n",
" if (len(word_a) < 1 or len(word_b) < 1 or len(word_a) != len(word_b)):\n",
" #print (\"False\")\n",
" return False\n",
" # To check the strings considering case sensitive \n",
" elif (is_case_sensitive == True):\n",
" #print (sorted(word_a))\n",
" #print (sorted(word_b))\n",
" # To sort the letters for comparision\n",
" if sorted(word_a) == sorted(word_b):\n",
" #print (\"True\")\n",
" return True\n",
" else:\n",
" #print (\"False\")\n",
" return False\n",
" # To check the strings considering case insensitive \n",
" else:\n",
" #print (sorted(word_a.lower()))\n",
" #print (sorted(word_b.lower()))\n",
" # To lower the case and sort the letters for comparision\n",
" if sorted(word_a.lower()) == sorted(word_b.lower()):\n",
" #print (\"True\")\n",
" return True\n",
" else:\n",
" #print (\"False\")\n",
" return False\n",
"\n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Slient\", \"listen\", False) # True"
Expand Down