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
83 changes: 64 additions & 19 deletions 02_assignments/assignment_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,34 +56,51 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"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",
"# Function to check if to words anagrams of each other (not case sensetive)\n",
"def anagram_checker(word_a, word_b):\n",
" # Your code here\n",
"\n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Slient\", \"listen\")"
" return sorted(word_a.lower()) == sorted(word_b.lower()) # Convert case to lower, sort letters in both words, and return result of comparison"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"anagram_checker(\"Slient\", \"Night\")"
"# Create and fulfill list of word pairs\n",
"text_pairs = [(\"Slient\", \"listen\"), (\"Slient\", \"Night\"), (\"night\", \"Thing\"), (-1,4242.555), (\"asdasd casd\", \"asdasd ca sd\"), (\"\",\"\"), (None, None)]"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n",
"False\n",
"True\n",
"worng input\n",
"False\n",
"True\n",
"worng input\n"
]
}
],
"source": [
"anagram_checker(\"night\", \"Thing\")"
"# Send each pair to anagram_checker() to check if it is an anagram \n",
"for pair in text_pairs:\n",
" # try/catch exeptions in case of wrong input in pairs\n",
" try:\n",
" print(anagram_checker(*pair))\n",
" except: print(\"worng input\")"
]
},
{
Expand All @@ -97,24 +114,52 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# Function to check if to words anagrams of each other (case sensetive)\n",
"def anagram_checker(word_a, word_b, is_case_sensitive):\n",
" # Modify your existing code here\n",
"\n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Slient\", \"listen\", False) # True"
" if is_case_sensitive == False: # Check if is_case_sensitive parameter equal False\n",
" return sorted(word_a.lower()) == sorted(word_b.lower()) # Convert case to lower, sort letters in both words and return result of comparison\n",
" else: return sorted(word_a) == sorted(word_b) #sort letters in both words and return result of comparison (remaining case)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"anagram_checker(\"Slient\", \"Listen\", True) # False"
"# Create and fulfill list of word with is_case_sensitive parameter for each pair\n",
"text_trinities= [(\"Slient\", \"listen\", False), (\"Slient\", \"Listen\", True), (\"Slient\", \"Night\", True), (\"night\", \"Thing\", False), (-1,4242.555, True), (\"asdasd casd\", \"asdasd ca sd\", False), (\"\",\"\", True)]"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n",
"False\n",
"False\n",
"True\n",
"worng input\n",
"False\n",
"True\n"
]
}
],
"source": [
"# For the list of Tuples, send each Tuple with pair of words and is_case_sensitive parameter as arguments to anagram_checker() and check if words pair is an anagram \n",
"for trinity in text_trinities:\n",
" try: # try/catch exeptions in case of wrong input \n",
" print(anagram_checker(*trinity))\n",
" except: print(\"worng input\")"
]
},
{
Expand Down Expand Up @@ -144,7 +189,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.9.15"
}
},
"nbformat": 4,
Expand Down
Loading