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
170 changes: 170 additions & 0 deletions assignment_1.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"#Part1 \n",
"def anagram_checker(word_a, word_b):\n",
" #Building the base Anagram Checker assuming the uppercase letters are same as lower case letters\n",
" word_a = word_a.lower()\n",
" word_b = word_b.lower()\n",
"\n",
" if sorted(word_a) == sorted(word_b):\n",
" return True\n",
" else:\n",
" return False"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Silent\", \"listen\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Silent\", \"Night\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"night\", \"Thing\")"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"#Part2 :\n",
"def anagram_checker(word_a,word_b,is_case_sensitive):\n",
"#compare words are anagrams and checking for case sensitivity.\n",
" if not is_case_sensitive:\n",
"\n",
" word_a = word_a.lower()\n",
" word_b = word_b.lower()\n",
"\n",
" if sorted(word_a) == sorted(word_b):\n",
" return True\n",
" else:\n",
" return False\n",
" \n",
" elif is_case_sensitive: \n",
" if sorted(word_a) == sorted(word_b):\n",
" return True\n",
" else:\n",
" return False\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Silent\", \"listen\", False)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Silent\", \"Listen\", True)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "dsi_participant",
"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.9.15"
}
},
"nbformat": 4,
"nbformat_minor": 2
}