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
115 changes: 96 additions & 19 deletions 02_activities/assignments/assignment_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"\n",
"Examples of anagrams:\n",
"* Silent and Listen\n",
"* Night and Think\n",
"* Night and Thing\n",
"\n",
"Example outputs:\n",
"```python\n",
Expand All @@ -56,36 +56,89 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"source": [
"# For testing purposes, we will write our code in the function\n",
"def anagram_checker(word_a, word_b):\n",
"# def anagram_checker(word_a, word_b):\n",
" # Your code here\n",
"\n",
"def anagram_checker(string1,string2):\n",
" s1=string1.replace(\" \",\"\").lower()\n",
" s2=string2.replace(\" \",\"\").lower()\n",
" return sorted(s1) == sorted(s2)\n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Silent\", \"listen\")"
"print(anagram_checker(\"Silent\", \"listen\"))"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Silent\", \"Night\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"night\", \"Thing\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Li!st en\", \"Si!le nt\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -97,24 +150,48 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"source": [
"def anagram_checker(word_a, word_b, is_case_sensitive):\n",
"## def anagram_checker(word_a, word_b, is_case_sensitive):\n",
" # Modify your existing code here\n",
"def anagram_checker(string1, string2, is_case_sensitive=False): ##by default the \"case sensitive switch is off, hence why is false, we dont care about upper or lower cases\"\n",
" if not is_case_sensitive: ##if we do care about upper/lower case\n",
" string1= string1.lower() ##when the switch is off then we turn all into lower cases because we dont care if they were upper or lower case\n",
" string2= string2.lower() ##if the switch is on we do nothing,letter keep their upper or lower case\n",
"\n",
" string1 = string1.replace(\" \",\"\") ##we remove the spaces\n",
" string2 = string2.replace(\" \",\"\")\n",
" \n",
" return sorted(string1) == sorted(string2) ##put the letters in alphabetical order\n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Silent\", \"listen\", False) # True"
"print(anagram_checker(\"Silent\", \"listen\", False)) # True"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n"
]
}
],
"source": [
"anagram_checker(\"Silent\", \"Listen\", True) # False"
"print(anagram_checker(\"Silent\", \"Listen\", True)) # False"
]
},
{
Expand All @@ -130,7 +207,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "new-learner",
"display_name": "python-env",
"language": "python",
"name": "python3"
},
Expand All @@ -144,7 +221,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.11.14"
}
},
"nbformat": 4,
Expand Down
46 changes: 46 additions & 0 deletions Untitled-1.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "64031f01",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1 + 1"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "python-env",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.14"
}
},
"nbformat": 4,
"nbformat_minor": 5
}